admin管理员组文章数量:1327927
I have a table, and usually i use this selector to apply odd and even row:
table.find('tbody tr:even').addClass('even');
table.find('tbody tr:odd').removeClass('even');
My Table has rows being inserted at various places, hence why i remove it from the odd rows.
I now have certain rows hidden using
jQueryTrObject.hide();
I want to apply the same styling as before, so that alternate rows, as far as the user is concerned are marked up odd and even, and i'd like it to take into account of hidden rows.
How do i write a selector to do this, for do i have to use the each and specifically check?
I have a table, and usually i use this selector to apply odd and even row:
table.find('tbody tr:even').addClass('even');
table.find('tbody tr:odd').removeClass('even');
My Table has rows being inserted at various places, hence why i remove it from the odd rows.
I now have certain rows hidden using
jQueryTrObject.hide();
I want to apply the same styling as before, so that alternate rows, as far as the user is concerned are marked up odd and even, and i'd like it to take into account of hidden rows.
How do i write a selector to do this, for do i have to use the each and specifically check?
Share Improve this question asked Jan 31, 2011 at 16:06 AndyAndy 1,4211 gold badge16 silver badges22 bronze badges4 Answers
Reset to default 6use the :visible
selector
table.find('tbody tr.even').removeClass('even');
table.find('tbody tr:visible:even').addClass('even');
Remember to use it first so that the :even
filter applies after it.
Try this out:
table.find('tbody tr').removeClass('even')
.filter(':visible:even').addClass('even');
Use a :not(:hidden)
selector
table.find('tbody tr:not(:hidden):even').addClass('even');
You can use the :visible selector to only markup visible row:
table
.find('tbody tr:visible:even')
.addClass('even')
.end()
.find('tbody tr:visible:odd')
.removeClass('even');
.end();
本文标签: javascriptJQuery Selector for table with hidden rowalternate row colouringStack Overflow
版权声明:本文标题:javascript - JQuery Selector for table with hidden row - alternate row colouring - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742253868a2441264.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论