开发者

multiple selector jquery

开发者 https://www.devze.com 2023-02-27 10:32 出处:网络
i\'ve got this ugly jquery selectors.. $(\'div img\').eq(3).css(\'padding-right\', \'0\'); //multiple of 4...

i've got this ugly jquery selectors..

$('div img').eq(3).css('padding-right', '0'); //multiple of 4...
$('div img').eq(7).css('padding-right', '0');
$('div img').eq(11).css('padding-right',开发者_如何学运维 '0');
$('div img').eq(15).css('padding-right', '0');

i have to get all imgages in positioned in 4^ and multiple-of-4 positions...

is there a better code than mine? :-)


Yes:

$('div img:nth-child(4n+3)').css('padding-right', '0');


You can use nth-child as illustrated here:

http://jsfiddle.net/YdsjY/

0

精彩评论

暂无评论...
验证码 换一张
取 消