且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当复选框为true或false时,从DOM中删除并重新添加

更新时间:2023-12-05 20:43:40

我不知道你是否有这个想法,但是通过应用以下选择器:

I'm not sure if you had this in mind, but by applying the following selector:

$('div.portfolio-item:visible:first').addClass("first-item"); 

您可以添加类:第一项为第一个可见的div(类投资组合项目),可用于为第一个div应用特殊样式。在这个答案中,我发现了:visible selector的有用性。

You can add the class: first-item for the first visible div (with class portfolio-item), that can be used to apply special styles for the first div. I discovered the usefulness of :visible selector at this answer.

总共有两行代码已经添加到 $ checkboxes.change 函数中:

Altogether, two lines of code have been added into $checkboxes.change function:

 $('div.portfolio-item').removeClass("first-item");

 $('div.portfolio-item:visible:first').addClass("first-item");

第一行刚刚清除以前的第一项选择。

The first line just clears the previous first-item selection.

小提琴