Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find relative path of a image tag javascript

I go through many problems regarding this,But couldn't find clear answer. I have image tag like this

<img src="images/abc.jpg"/>

But when I called in side javascript,

var imgs = document.getElementsByTagName("img");
alert(imgs[0].src);

it shows the src as "http://localhost/myProject/images/abc.jpg" But I need only get the relative path ("images/abc.jpg")some how. Some body help me...

like image 327
shamika Dharmasiri Avatar asked Jan 08 '13 18:01

shamika Dharmasiri


1 Answers

You may try to get the element src attribute value, not the src property:

imgs[0].getAttribute("src");  // "images/abc.jpg"
like image 138
VisioN Avatar answered Sep 17 '22 01:09

VisioN