There is a HTML code.

<ul class="br"> <li class="bj"> <table> <tbody> <tr> <td class="u"> <a href="/1">1</a> </td> </tr> </tbody> </table> </li> <li class="bj"> <table> <tbody> <tr> <td class="u"> <a href="/1">1</a> </td> </tr> </tbody> </table> </li> </ul> 

How to get a URL for example 1 links to a variable? I tried to do so

 elementList = window.content.document.querySelectorAll('.br .u a')[0].innerHTML; alert(elementList); 

Does not work.

And it would not be bad to count them all and put them in a variable. But this is the second time, the main thing is to get a certain link.

I tried to count it this way, but not what does not work.

 elementList = window.content.document.querySelectorAll('.br .u a'); alert(elementList.length); 
  • jquery not using? - Andrei
  • not, only pure JavaScript - Anatoly
  • one
    And who said that ul>td are built into the correct DOM? Either ul>li , or draw a normal table - vp_arth
  • @vp_arth finished painting - Anatoly
  • 3
    And document.querySelectorAll('.br .u a')[0].getAttribute('href') doesn't work? - vp_arth

1 answer 1

Here is the code where I saved the url from the ul.br list to the ul.br :

 var matches = document.querySelectorAll("ul.br a"); var array_tag_a = []; for (var i = 0; i < matches.length; i++) { array_tag_a.push (matches[i].getAttribute('href')); } console.log(array_tag_a); 
 <ul class="br"> <li class="bj"> <table> <tbody> <tr> <td class="u"> <a href="/1">1</a> </td> </tr> </tbody> </table> </li> <li class="bj"> <table> <tbody> <tr> <td class="u"> <a href="/1">1</a> </td> </tr> </tbody> </table> </li> </ul> 

  • Thanks, everything plows. - Anatoly
  • @ Anatoly No thanks) - x_ror