jquery - :nth-child() selector, 多个第 n 个 child

标签 jquery css jquery-selectors css-selectors

我正在尝试在表格标题上获取点击事件,这使用 jQuery 很容易。 我希望点击事件在除第一个标题之外的所有标题上都处于事件状态。

我正在使用 CSS 的 :nth-child() 属性转义第一个 header 。

我就是这样做的

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

我没有得到结果。我可以用 :nth-child() 本身来做更好的方法吗?

最佳答案

你可以使用:not

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

你可以使用:gt(0)

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

评论回复

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

Official Document

示例

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

关于jquery - :nth-child() selector, 多个第 n 个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15963267/

相关文章:

css - react 模态动画模态关键帧

css - 为 <ul> 或 <ol> 编写标题/标题的最佳方法是什么,就像我们在 <table> 中有 <caption> 一样?

javascript - 如何使用 jQuery 的 .not 和 :contains in case of multiple values?

javascript - 为什么没有找到元素,除了在 jsfiddle 中?

javascript - 为什么我的 jQuery 过滤器函数中的测试没有按预期工作?

javascript - Slick Grid 中的数据更新

javascript - 为什么固定 block 在滚动时闪烁?

html - 确保在 angularjs 中打印预览之前加载图像

javascript - 如何查找具有某个 JQuery 类的 Div 数量?

jquery - 以 $(this) 目标的选择器开始