Drop gt() , as I assume it will be a little slower than :first .
Use not() in combination with :first and :last :
$('table#tbl > tbody > tr').not(':first').not(':last').addClass('highlight');
Most browsers automatically add the tbody element to the table tbody if this is missing, so the immediate child selector failed to fail; there were no <tr> elements as immediate children of the <table> .
I am not 100% sure that all browsers do this, so it would be safer to just add <tbody> manually. Otherwise, you need to sniff a little and can not do it as one liner:
if($('table#tbl > tbody').size() > 0) { $('table#tbl > tbody > tr').not(':first').not(':last').addClass('highlight'); } else { $('table#tbl > tr').not(':first').not(':last').addClass('highlight'); }
Hope this solves your problem!
Tatu Ulmanen Feb 12 '10 at 17:16 2010-02-12 17:16
source share