how to loop on hrefs?
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]);
}
精彩评论