Roberto
Roberto

Reputation: 809

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

Upvotes: 4

Views: 823

Answers (2)

Steve Wellens
Steve Wellens

Reputation: 20620

You can use nth-child as illustrated here:

http://jsfiddle.net/YdsjY/

Upvotes: 1

Pointy
Pointy

Reputation: 413702

Yes:

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

Upvotes: 8

Related Questions