Skip to content Skip to sidebar Skip to footer

Get The Href Attribute For Each Link In A Section Of Html

Solution 1:

Solution 2:

Solution 3:

Solution 4:

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"