I am trying to get the src from this jquery html().
So using jquery html() my alert shows this output
what I want is the src. See code below:
var $boxes = $(".slideWrap"),
var hdnImg = $boxes.first().show();
var p = hdnImg.html(); //OUTPUTS <img src="../image090.png" id="ctl00_ContentPlaceHolder1__Graphics1">
alert(p.attr("src")); // DOES NOT WORK??
Why is p.attr(“src”) does not work? I am trying to get the html and then getting the src from the html.
Any one please help?
According to the documentation
.html()returns a string. Strings don’t have an.attr()method.If you want the attribute from the element, the use
.attr()on the element that has the attribute you want.Here’s another part of the problem…
Because the output shows the HTML of the
<img>, and the.html()method returns the HTML content, then that means the image is nested.To get the image, you need to traverse down to it. Do this instead…