如何从jQuery中的父项中选择所有孩子(任何级别)? [英] How to select ALL children (in any level) from a parent in jQuery?

查看:719
本文介绍了如何从jQuery中的父项中选择所有孩子(任何级别)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从父节点 .unbind()所有元素。

I have to .unbind() all elements from a parent node.

如何选择所有孩子(在任何级别)从父母?

How can I select all children (at any level) from a parent?

试过:

$('#google_translate_element *').unbind('click');

但它只适用于第一个孩子的级别...

but it works only for the first children's level...

这里有一个测试用例

推荐答案

使用 jQuery.find()查找超过

Use jQuery.find() to find children more than one level deep.


.find()和.children()方法是相似的,除了
后者只能沿着DOM树向下移动一个级别。

The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.



$('#google_translate_element').find('*').unbind('click');

您需要'*' code> find():

You need the '*' in find():


与其他树遍历方法不同,选择器在调用.find()时需要
表达式。如果我们需要检索
所有的后代元素,我们可以通过通用选择器
'*来完成这个。

Unlike in the rest of the tree traversal methods, the selector expression is required in a call to .find(). If we need to retrieve all of the descendant elements, we can pass in the universal selector '*' to accomplish this.

这篇关于如何从jQuery中的父项中选择所有孩子(任何级别)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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