jQuery nth-child nth-of-type Not Working
jQuery nth-child nth-of-type Not Working
我需要在x个元素之后插入一个clearfixdiv,这样我就可以得到很好的格式化列。
我已经尝试了:nth-child
和:nth-of-type
,我只在前x项之后添加了一个div。
$('#content .product-layout:nth-child(3)').after('<div class="clearfix visible-lg"></div>');
在第三个。product-layoutdiv之后创建一个div。
$('#product-row div:nth-child(3)').after('<div class="clearfix visible-lg"></div>');
在第三个。product-layoutdiv之后创建一个div。
我需要在每个现有的第3个product-layoutdiv之后创建div。
我到底做错了什么?
您缺少n
以选择#content
的product-layout
类的每第三个子元素:
$('#content .product-layout:nth-child(3n)').after('<div class="clearfix visible-lg"></div>');
// ---------------------------------- ^ here
您需要使用3n
用于重复元素列表,:nth-child(3)
只选择第三个子元素,而:nth-child(3n)
将选择3,6,9…等
$('#product-row div:nth-child(3n)').after('<div class="clearfix visible-lg"></div>');
演示:小提琴
- : nth-child
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working