Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery odd even on nested list

Tags:

jquery

php

list

jQuery:

$("li:even div").removeClass("odd even").addClass("odd");
$("li:odd div").removeClass("odd even").addClass("even");​

http://jsfiddle.net/hashie5/vk6rZ/

As you can see in the fiddle, odd/even does not work properly, what am I doing wrong?

like image 382
Ruben Avatar asked May 15 '12 09:05

Ruben


Video Answer


3 Answers

Here is a working example

http://jsfiddle.net/joycse06/vk6rZ/4/

target immediate children (divs)

$("li:even > div").removeClass("odd even").addClass("odd");
$("li:odd > div").removeClass("odd even").addClass("even");​
like image 104
Prasenjit Kumar Nag Avatar answered Sep 28 '22 01:09

Prasenjit Kumar Nag


look at the li:even>div instead of li:even div

$("li:even>div").removeClass("odd even").addClass("odd");
$("li:odd>div").removeClass("odd even").addClass("even");
like image 33
Adam Lukaszczyk Avatar answered Sep 27 '22 23:09

Adam Lukaszczyk


You can use this: http://jsfiddle.net/hashie5/vk6rZ/

$("li:even > div").removeClass("odd even").addClass("odd");
$("li:odd > div").removeClass("odd even").addClass("even");
like image 27
Nildarar Avatar answered Sep 28 '22 00:09

Nildarar