views:

32

answers:

1

so , what i need is 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 ! by 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></li>

+1  A: 

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]);
}
Brian McKenna
There is a problem, the length of the links is only 1 !?doesn't that have to do anythign with the nth-child(2) ?
msheshtawy
My mistake, I thought that the selector was fine. I just edited my answer so that it gets all of the links.
Brian McKenna
yeah it worked :D i did it with ('#courses_menu > ul >li >a ); Thanks alot
msheshtawy