add alternating classes to existing jquery object -


i know can following:

$('#mytable').find('tr:odd').removeclass('even'); $('#mytable').find('tr:even').addclass('even'); 

what if have $('#mytable').find('tr'). how efficiently add alternating classes?

filter() works selector argument using function argument

var $rows = $('#mytable tr');//cache rows // specific class of rows $rows.filter('.even').dosomething().dosomethingelse() 

for specific case, do:

$(function() {   var $rows = $('table tr'); //cache rows   // specific class of rows   $rows.removeclass('even').filter(':even').addclass('even') }) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -