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

I am trying to get a click event on table headers and this is easy using jQuery. I want the click event to be active in all headers except the first heading.

I run the first header with: nth-child () CSS property.

This is how I do it -

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

I do not get the result. Is there a better way to do this with :nth-child() ?

+4
source share
2 answers

You can use :not .

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

OR

You can use :gt(0)

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

A comment

For an odd selector, you can use the selector :odd jQuery .

Official Document

Example

 $('th:not(:odd)').click(function(){ 
+9
source

What about

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

All Articles