tags:

views:

46

answers:

5
+1  Q: 

jQuery nth child

Is it possible to get jQuery to do the same job as nth:child(odd)?

So that I can add zebra lines to tables in browsers like IE6?

If so can someone help?

+1  A: 

You are using the wrong syntax: $(":nth-child(odd)") or shorter $(":odd")

http://api.jquery.com/odd-selector/

http://api.jquery.com/nth-child-selector/

RoToRa
+1  A: 
$("tr:nth-child(odd)").addClass("odd_row");
Brian Ray
+2  A: 

You can use the :odd selector to select odd table rows, like so:

$("tr:odd").css("background-color", "#DDD");
Ryan Brunner
A: 
$('.class:nth-child(odd)')...;

http://api.jquery.com/nth-child-selector/

Floyd
+1  A: 

Just do ("table tr:odd") or ("table tr:even"). Try using http://api.jquery.com where most of these types of questions are answered.

Rune Hammerskov