How to select table cells without selecting nested table cells in jQuery

孤人 提交于 2019-12-06 09:26:56

I'd use the children selector, which only selects the immediate children matching the expression. To make it easy to select just the outer table, I'd give it a name. NOTE: this won't work with your sample as I've added in the selectors for thead, tbody, and tfoot as you indicate you will have in production. Adjust accordingly for your sample.

$('table#namedTable').children('tbody,thead,tfoot')
                     .children('tr')
                     .children('td')

Give the outermost table an id of "Outer":

$("table#Outer > td").text("selected");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!