寻找包含当前节点的jQuery find(..)方法 [英] Looking for jQuery find(..) method that includes the current node

查看:61
本文介绍了寻找包含当前节点的jQuery find(..)方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery find(..)遍历方法不包括当前节点-它开始与当前节点的子代.调用在匹配算法中包含当前节点的查找操作的最佳方法是什么?查看文档,没有什么立即跳出来.

The jQuery find(..) traversal method doesn't include the current node - it starts with the children of the current node. What is the best way to call a find operation that includes the current node in its matching algorithm? Looking through the docs nothing immediately jumps out at me.

推荐答案

对于jQuery 1.8及更高版本,您可以使用 .addBack() .它需要一个选择器,因此您不需要过滤结果:

For jQuery 1.8 and up, you can use .addBack(). It takes a selector so you don't need to filter the result:

object.find('selector').addBack('selector')

在jQuery 1.8之前,您一直受困于 .andSelf() (现已弃用并删除),然后需要过滤:

Prior to jQuery 1.8 you were stuck with .andSelf(), (now deprecated and removed) which then needed filtering:

object.find('selector').andSelf().filter('selector')

这篇关于寻找包含当前节点的jQuery find(..)方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆