javascript - 我需要一个更好的 jQuery 选择器来减少 children() 调用

标签 javascript jquery jquery-selectors

目前我正在使用 $('table').children('tfoot').children('tr').children('td');

获取tfoot中唯一的td。

我不喜欢使用 .children() 3 次,

有没有更好的办法?


编辑
轻微修正 选择器其实就是

var table = this;
$(table).children('tfoot').children('tr').children('td');

因为这是在 jquery 插件中。

最佳答案

$('table > tfoot > tr > td')

children()在直系子女中搜索,所以为了复制这个,我使用了 direct descendant selector (>)。

更新

根据您的更新,您可以...

$(table).find(' > tfoot > tr > td')

或者您可以将 table 替换为 this

很高兴你是thinking of the children .

关于javascript - 我需要一个更好的 jQuery 选择器来减少 children() 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4222270/

相关文章:

javascript - 查找指定td内输入字段的特定值

JavaScript ES6 : use case for destructuring rest parameter

javascript - Google Maps API 未显示引导元素和固定导航栏

javascript - 如何根据输入的内容更改输入的标题?

jQuery : point circle set position menu hover/hover out and click navigation link

jquery - Jquery中获取Span id属性值

javascript - 请求失败 SOAP WS 返回代码 404

javascript - 错误: Uncaught TypeError

javascript - 如何检查另一个元素中的最后一个元素是否获得焦点

javascript - 使用数据属性 - 构建一个列表并查看是否存在