var x = document.querySelectorAll(".indexed-biz-name");
for (i = 0; i < x.length; i++) {
document.write(x[i].innerHTML + "<br>");
}
When i run this code through greasemonkey it gives me output
which is hyperlink in it. I want to extract the url within a same working.
var x = document.querySelectorAll(".indexed-biz-name");
for (i = 0; i < x.length; i++) {
document.write(x[i].innerHTML + "<br>");
}
When i run this code through greasemonkey it gives me output
which is hyperlink in it. I want to extract the url within a same working.
- 4 x[i].href ? and please dont use document.write. its awful – Jonas Wilms Commented Jan 28, 2017 at 13:37
- @Jonasw it's I think only for his debugging. :) that would do i guess – Roljhon Commented Jan 28, 2017 at 13:38
- unclear of what you're asking – Adam Wolski Commented Jan 28, 2017 at 13:39
-
Click the
<>
and create a minimal reproducible example – mplungjan Commented Jan 28, 2017 at 13:39
1 Answer
Reset to default 3Below is a snippet that does that you want
var links = document.querySelectorAll(".indexed-biz-name");
document.write('</br></br>')
for (i = 0; i < links.length; i++) {
document.write(links[i].getAttribute("href")+'</br>');
}
<a href="bla" class="indexed-biz-name">link1</a>
<br/>
<a href="blabla" class="indexed-biz-name">link2</a>
<br/>
<a href="blablabla" class="indexed-biz-name">link3</a>