Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:nth-child() selector, multiple nth-child

I am trying to get click event on table headers and that is easy with jQuery. I want click event to be active on all headers except first header.

I am escaping first header with :nth-child() property of CSS.

This is how i am doing-

$(function(){
$('th:nth-child(2 3 4 5)').click(function(){
$(this).CSS("font-weight","bolder");
});
});

I don't get result. Is there any better way i could do it with :nth-child() itself?

like image 325
Manoz Avatar asked Dec 27 '22 05:12

Manoz


2 Answers

You can use :not.

$('th:not(:first-child)').click(function(){

OR

You can use :gt(0)

$('th:gt(0)').click(function(){

Comment Response

For odd selector you can use :odd jQuery selector.

Official Document

Example

$('th:not(:odd)').click(function(){
like image 188
Dipesh Parmar Avatar answered Dec 28 '22 22:12

Dipesh Parmar


How about

$('th:nth-child(n+2)')
like image 29
Musa Avatar answered Dec 28 '22 20:12

Musa