开发者

how to loop on hrefs?

开发者 https://www.devze.com 2022-12-17 00:18 出处:网络
I need to get some links from the following code. I managed to reach the href of the first one by using:

I need to get some links from the following code. I managed to reach the href of the first one by using:

var link=doc.querySelector('#courses_menu > ul > li:nth-child(2) a');

Now I need all these href's. With a loop maybe?

Here is the source I need to work on:

<ul class="tools-menu-ul">
  <li class="tools-menu-back"><a href="#main_menu" class="controls">back</a></li>
     <li><a title="Neural Networks (Elective for MET)" href="Courses/CourseEdition.aspx?crsEdId=109"> CSEN 1005</a></li>

      <li><a title="Systems-on-a-Chip (Elective for MET)" href="Courses/CourseEdition.aspx?crsEdId=111">ELCT 1002 </a></li>

      <li><a title="Seminar on Self Reference" href="Courses/CourseEdition.aspx?crsEdId=115"> CSEN 1009</a></li>

      <li><a title="Seminar on Handheld Augmented Reality" href="Courses/CourseEdition.aspx? crsEdId=120"> DMET 1011 </a><开发者_C百科;/li>
</ul>


You need to use querySelectorAll instead.

var links = doc.querySelectorAll('#courses_menu > ul > li a');

for(var i = 0; i < links.length; i++) {
    alert(links[i]);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号