in this opportunity I seek to achieve the following; I have a row selected by clicking on its first element th
to which I gave a class and with the querySelectorAll
and map
I formulate an event for each of them, now well, how do I select the th
of that selected row, that is, only the th
that remain in purple when doing click
in the first th
of each row.
let getSelectorA = s => document.querySelectorAll(s);
Array.from(getSelectorA('.ev')).map((e,i) => {
e.addEventListener('click', event => {
Array.from(getSelectorA('tr'))[i +1].classList.toggle('purple');
});
});
table, th, td {
border: 1px solid black;
padding: 1rem;
}
.purple{
background: purple;
}
<table>
<thead>
<tr>
<th>by</th>
<th>Date</th>
<th>Tras</th>
</tr>
</thead>
<tbody>
<tr>
<th class="ev">byOne</th>
<th>dateOne</th>
<th>trasOne</th>
</tr>
<tr>
<th class="ev">byTwo</th>
<th>dateTwo</th>
<th>trasTwo</th>
</tr>
<tr>
<th class="ev">bylast</th>
<th>datelast</th>
<th>traslast</th>
</tr>
</tbody>
</table>
By doing the same transform them Array
I can not divide them and get what I want the truth I pause at that point ...