简体   繁体   中英

multiple selector jquery

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? :-)

是:

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

You can use nth-child as illustrated here:

http://jsfiddle.net/YdsjY/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM