最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I want to extract href value from hyperlink through document.querySelector - Stack Overflow

programmeradmin0浏览0评论
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.

Share Improve this question edited Jan 28, 2017 at 13:39 mplungjan 179k28 gold badges182 silver badges240 bronze badges asked Jan 28, 2017 at 13:34 Ahmed HassanAhmed Hassan 1101 gold badge2 silver badges7 bronze badges 4
  • 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
Add a ment  | 

1 Answer 1

Reset to default 3

Below 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>

发布评论

评论列表(0)

  1. 暂无评论