164
rated 0 times
[
170]
[
6]
/ answers: 1 / hits: 17640
/ 8 Years ago, tue, january 17, 2017, 12:00:00
I'm trying to get a list of only the first links per row in one wikipedia table with querySelectorAll but I am not sure why the :first-child selector is not working. I know there is other ways to do it but I want to know if there is a solution to this specific problem with the querySelectorAll function.
see my attemps below the html:
<table class='wikitable'>
<tr>
<td>
<a href= title=>John doe</a>
</td>
<td>
<a href= title=>other link</a>
</td>
</tr>
<tr>
<td>
<a href= title=>Mary Jane</a>
</td>
<td>
<a href= title=>another link</a>
</td>
</tr>
</table>
My Code:
let list = document.querySelectorAll(('.wikitable tr:first-child td:first-child a'));
the previous code is just returning a node with one element:
<a href= title=>John doe</a>
Instead a list:
<a href= title=>John doe</a>
<a href= title=>Mary Jane</a>
More From » selectors-api