I’m trying to get the value of href from an anchor. The code looks like this
var html = "<a href='http://path/to/file.pdf'>File</a>";
alert(jQuery("a",html).attr("href"));
The only output I get is ‘undefined’.
I’m want to get “http://path/to/file.pdf“.
Any help is greatly appreciated.
Try:
Or if the
<a>tag is deeper in the html than your example:The
jQuery()function will convert HTML strings into DOM objects, and return a jQuery object containing them for you.