Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a JQuery event to determine when an element's list of children has changed?

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.

like image 284
Achilles Avatar asked Feb 17 '11 18:02

Achilles


People also ask

How do you get children of children in jQuery?

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.

Which event is triggered when a form field is changed?

Whenever the value of a form field changes, it fires a "change" event.

How do you get the children of the $( this selector?

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.


1 Answers

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.

like image 168
rsp Avatar answered Sep 23 '22 22:09

rsp