Reputation: 17
I am searching for some JavaScript that does the following:
This is the html code from where I want to extract the image url
<img id="icImg" class="img img500" itemprop="image" src="http://i.ebayimg.com/images/g/6w8AAOSwQgpW~oRP/s-l500.jpg" onload="picTimer=new Date().getTime();" clk="0" alt="Leather-Jacket-Men-Sheep-Skin-Limited-Edition-Bomber-Slim-fit-Jacket-Stylish-36" mskuskip="false">
Now my aim is to copy that http://i.ebayimg.com/images/g/6w8AAOSwQgpW~oRP/s-l500.jpg
to a variable
How can I do it using JavaScript only?
Upvotes: 2
Views: 211
Reputation: 27232
try this it will work :
jQuery :
var url = $("#icImg").attr("src");
Javascript :
var url = document.getElementById("icImg").getAttribute("src");
Working fiddle : https://jsfiddle.net/zfc66L46/
Upvotes: 0
Reputation: 906
I guess this is what you're looking for
var url = document.getElementById("icImg").getAttribute("src");
Upvotes: 1