I'm hoping to find a JQuery event that will tell me when an element collection has grown or shrunk after the addition/removal of a child element.
jQuery children() MethodThe 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.
Whenever the value of a form field changes, it fires a "change" event.
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.
What you are looking for are the DOMNodeInserted and DOMNodeRemoved events.
For example, after you bind to a DOMNodeInserted event of a list:
$('ol').bind('DOMNodeInserted', function() {
alert('node inserted');
});
and then another list item is inserted:
$('ol').append('<li>x</li>');
the event is fired.
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