Manoz
Manoz

Reputation: 6587

: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?

Upvotes: 4

Views: 2073

Answers (2)

Dipesh Parmar
Dipesh Parmar

Reputation: 27364

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(){

Upvotes: 9

Musa
Musa

Reputation: 97672

How about

$('th:nth-child(n+2)')

Upvotes: 1

Related Questions