我需要在 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。
我需要在每个第三个现有产品布局 div 之后创建 div。
我到底做错了什么?
最佳答案
您缺少 n
来选择 #content
的 product-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/