[英]:not and :first-child
In a for
loop I replace the content of a div with another and I add a class to it. 在
for
循环中,我将div的内容替换为另一个,然后向其中添加一个类。
Example: 例:
<div class="page">Loading..</div>
<div class="page">Loading..</div>
<div class="page">Loading..</div>
And jQuery: 和jQuery:
$(".page:not(.active):first-child").html("Loaded.").addlass(".active");
It works only for the first. 它仅适用于第一个。 How can I do it?
我该怎么做? They have to be all "Loaded" in the end.
最后必须全部“加载”它们。
像这样?
$(".page:not(.active)").html("Loaded.").addClass("active");
Replace it with 替换为
$(".page:not(.active)").eq(0).html("Loaded.").addClass("active");
To add a class you don't need the dot and :first-child
only works for the first child element while you need the first element of the filtered set. 要添加一个类,您不需要点,
:first-child
仅适用于第一个子元素,而您需要过滤组的第一个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.