How to select all except the first occurence of a

2019-08-04 13:31发布

I'm trying to select the all anchor tags in a table that have the class .action except the first one but can't seem to do it using the css filters.

$(".action:not(:first)").css("visibility", "hidden");

Has no effect

I have also tried doing each one explicitly like such

$("tr:contains('Second') .action").css("visibility", "hidden");

but this makes all .action hidden

Solved!

$('.action:not(:first, :nth(2))').css("visibility", "hidden");

1条回答
孤傲高冷的网名
2楼-- · 2019-08-04 14:06

Your code should work.

You might have to adjust your selector so that only the .action elements inside the table are selected.


You can use .slice [docs], but if your selector does not work, this won't either:

$(".action").slice(1).css("visibility", "hidden");
查看更多
登录 后发表回答