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
Post a Comment