Get The Href Attribute For Each Link In A Section Of Html
I've written the following jQuery to loop through each of the objects in a section of HTML: $('.chapterindex' + key + ' div.link a').each(function(intIndex){ alert('Num
Solution 1:
Try this:
$(".chapterindex" + key + " div.link a").each(
function(intIndex){
alert( "Numbered index: " + intIndex );
var href = $(this).attr('href');
});
});
Solution 2:
You can access it through $(this).attr('href')
Solution 3:
$(".chapterindex" + key + " div.link a").each(
function(intIndex){
alert( "Numbered index: " + $(this).attr("href") );
});
});
Solution 4:
$(".chapterindex" + key + " div.link a").each(function () {
alert(this.href);
});
Solution 5:
Do you want the full HREF or the HREF as it appears in the tag?
The jQuery object method $(this).attr('href')
proposed by some people will return whatever is set as the HREF attribute in the tag.
The DOM node property method this.href
proposed by John will return the fully-qualified URL.
So given a link <a href="/resources/foo.ext">Foo</a>
, the jQuery method will return "/resources/foo.ext" while the other method will return "http://mysite.ca/currentpath/resources/foo.ext".
So it just depends on what you need returned.
Post a Comment for "Get The Href Attribute For Each Link In A Section Of Html"