how do I add classes for Odd columns in a data table whose eq is greater than 3 ?? this is the code which i tried out, and its giving the class to the tr. Is there any neat way to achieve it ??
$('.dataTable tr').each(function() {
console.log($(this))
if ( $(this).children('td:odd') || $(this).children('td:gt(3)') ) {
$(this).addClass('oddColumn');
// how do I access the td element here ??
}
});
Are you looking for something like this?
Example: http://jsfiddle.net/ambiguous/AQdY8/
Note that jQuery’s
nth-childselector matches the CSS version:A side effect of this is that it indexes from 1 rather than 0 as the other jQuery selectors: