I have to .unbind()
all elements from a parent node.
How can I select all children (at any level) from a parent?
Tried :
$('#google_translate_element *').unbind('click');
but it works only for the first children's level...
Here there is a test case
Definition and Usage. The children() method returns all direct children of the selected element. The DOM tree: This method only traverse a single level down the DOM tree. To traverse down multiple levels (to return grandchildren or other descendants), use the find() method.
jQuery children() method is used to get the direct children of the selected HTML element. You can use children() method to traverse through the child elements of the selected parent element.
The ("parent > child") selector selects all elements that are a direct child of the specified element.
Answer: Use the jQuery find() Method You can use the find() method to get the children of the $(this) selector using jQuery. The jQuery code in the following example will simply select the child <img> element and apply some CSS style on it on click of the parent <div> element.
Use jQuery.find() to find children more than one level deep.
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');
You need the '*'
in 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.
I think you could do:
$('#google_translate_element').find('*').each(function(){ $(this).unbind('click'); });
but it would cause a lot of overhead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With