Answers for "javascript get all a href links"

0

get all href from html

var arr = [], l = document.links;
for(var i=0; i<l.length; i++) {
  arr.push(l[i].href);
}
Posted by: Guest on December-03-2020
-1

get all links from html javascript

var rawHTML = '<html><body><a href="foo">bar</a><a href="narf">zort</a></body></html>';

var doc = document.createElement("html");
doc.innerHTML = rawHTML;
var links = doc.getElementsByTagName("a")
var urls = [];

for (var i=0; i<links.length; i++) {
    urls.push(links[i].getAttribute("href"));
}
alert(urls)
Posted by: Guest on December-05-2020

Browse Popular Code Answers by Language