How to select ALL children (at any level) from parent in jQuery?

I have .unbind() all the elements from the parent node.

How can I choose all the children (at any level) from the parent?

I tried:

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

but it works only for the first level of children ...

There is a test case here

+47
javascript jquery dom html
04 Oct 2018-11-11T00:
source share
2 answers

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

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

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

You need '*' in find() :

Unlike other tree traversal methods, an expression selector is required when calling .find (). If we need to get all the elements of the offspring, we can go through the '*' universal selector to accomplish this.

+95
04 Oct 2018-11-11T00:
source share

I think you could do:

 $('#google_translate_element').find('*').each(function(){ $(this).unbind('click'); }); 

but it will cause a lot of overhead

+16
Oct 04 2018-11-11T00:
source share



All Articles