Column selection (jQuery)

$('.table tbody td:eq(3)').addClass('col4');

.. works, but selects only the first cell, not all the cells in the column.

+3
source share
2 answers

Try:

$(".table tbody td:nth-child(4)").addClass("col4");

Note: I put 4 here because it is :eq(n)based on zero and :nth-child(n)is unidirectional.

You stumbled upon a key difference between the two. eq(3)will return exactly one element, the fourth of the entire set. Just as it :firstreturns only one element (max), while it :first-childcan return a lot.

+13
source

Source: https://habr.com/ru/post/1726345/


All Articles