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

2 Answers 2

8

Yes:

$('div img:nth-child(4n+3)').css('padding-right', '0');
Sign up to request clarification or add additional context in comments.

1 Comment

Very nice! +1! (SO won't allow comments with length <15)
1

You can use nth-child as illustrated here:

http://jsfiddle.net/YdsjY/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.