gpt4 book ai didi

javascript - jQuery nth-child nth-of-type 不工作

转载 作者:行者123 更新时间:2023-11-29 22:03:03 24 4
gpt4 key购买 nike

我需要在 x 数量的元素之后插入一个 clearfix div,以便我可以获得格式良好的列。

我已经尝试了 :nth-child:nth-of-type 并且我只在前 x 个项目之后添加了一个 div。

$('#content .product-layout:nth-child(3)').after('<div class="clearfix visible-lg"></div>');

在第三个 .product-layout div 之后创建一个 div。

$('#product-row div:nth-child(3)').after('<div class="clearfix visible-lg"></div>');

在第三个 .product-layout div 之后创建一个 div。

我需要在每第 3 个现有产品布局 div 之后创建 div。

我到底做错了什么?

最佳答案

您缺少 n 来选择 #contentproduct-layout 的每三个子元素:

$('#content .product-layout:nth-child(3n)').after('<div class="clearfix visible-lg"></div>');
// ---------------------------------- ^ here

关于javascript - jQuery nth-child nth-of-type 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22553536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com