Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Absolute source path with jQuery

This code gives something like ../movies/1.png, the exact src attribute:

$("img").attr("src");

How do I get absolute path of an image with jQuery?

I want to get something like http://site.com/movies/1.png, not ../movies/1.png

like image 771
James Avatar asked May 30 '11 22:05

James


Video Answer


1 Answers

This can easily be done by accessing the .src property directly on the <img>:

$('img')[0].src;

example: http://jsfiddle.net/9mKz2/

(I didn't test it on all browser right now)

like image 117
jAndy Avatar answered Oct 26 '22 23:10

jAndy