:nth-​​child()选择器,多个nth-child

Man*_*noz 4 css jquery css-selectors jquery-selectors

我试图在表头上获取click事件,使用jQuery很容易.我希望点击事件在除第一个标题之外的所有标题上都是活动的.

我正在使用CSS的nth-child()属性转义第一个标头.

这就是我在做的事情 -

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

我没有得到结果.有没有更好的方法可以自己做到这一点:nth-child()

Dip*_*mar 9

你可以用:not.

$('th:not(:first-child)').click(function(){
Run Code Online (Sandbox Code Playgroud)

要么

您可以使用 :gt(0)

$('th:gt(0)').click(function(){
Run Code Online (Sandbox Code Playgroud)

评论回复

对于奇数选择器,您可以使用:odd jQuery选择器

Official Document

$('th:not(:odd)').click(function(){
Run Code Online (Sandbox Code Playgroud)