Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Links in HTML Document using Javascript/jQuery

This is a challenge for any Javascript/jQuery ninjas out there:

What is the best way (using aforementioned languages), to find all of the links in an HTML document and return them all?

In other words, a function that like this - findLinks(document.html.innerHTML) that would return all links found in that HTML.

Thanks,

DLiKS

like image 946
DLiKS Avatar asked Jan 21 '23 15:01

DLiKS


1 Answers

Well, you could fiddle around with a chunky library (and it might be a good idea to do that if you end up wanting to do interesting things to manipulate the results), but just to get the links I think I'd stick to DOM 0:

document.links
like image 192
Quentin Avatar answered Jan 31 '23 05:01

Quentin