如何通过选择器仅选择缓存的jQuery上下文的直接子体
How to select only direct descendants of cached jQuery context by selector
我有一个缓存的jQuery对象。。。
$main = $('#main');
我想选择所有标签名为"span"的直接子项。。。
$('span', $main); // this selects all descendants, not all direct children
$(' > span', $main); // this does not work at all
我知道我可以做$('#main > span')
,它工作得很好,但我想重用缓存的选择器。
如何从缓存选择器中仅选择直接子项?
$main.children('span')
使用类似$main.children("span")
的jQuery children(selector)
函数获取更多信息:https://api.jquery.com/children/
相关文章:
- 使用JQuery的动态上下文菜单
- JQuery在单击正文时隐藏上下文菜单
- JQuery上下文菜单显示/隐藏问题
- 如何使用jQuery上下文参数
- 动态上下文菜单不显示在jQuery中
- 保留此内容并保留 jQuery 上下文
- jQuery Waypoints 上下文在 Safari 或 Chrome 中不起作用
- jQuery移动触摸事件处理,此关键字上下文,并正确使用闭包
- JQuery widget:在子 widget 中设置上下文
- 在使用jQuery.on时保持上下文
- Jquery - ajax 回调的上下文不遵循提供的上下文参数
- 在jQuery-UI插件中调用函数的上下文是错误的
- 上下文菜单的 Jquery 停止事件
- 从 Jquery 上下文菜单项的下拉列表中获取所选值,选择更改事件
- 从上下文菜单打开 JQuery/Bootstrap 对话框
- Javascript/jQuery 范围和上下文问题,当试图操作对象的“引用”时
- 如何更改jQuery默认上下文
- 在使用ng repeat和limit to时,jQuery中的上下文出现错误,并从tether.js获得工具提示
- 获取父函数的上下文-jquery
- 如何获得.js文件上下文jQuery $.接收时不执行Ajax