Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When adding an element to a list what is the best way to trigger this event [duplicate]

Possible Duplicate:
How to identify when the DOM has been changed?

Let's suppose I have access to the <ul> element $(ul#mylist).
How can I trigger the event when some item is added to the list.

I tried the following but actually it does not work.

$('ul#mylist').change(function () {
    console.log('added an element');
});
like image 272
Lorraine Bernard Avatar asked Oct 05 '12 15:10

Lorraine Bernard


1 Answers

You can try listening to DOMNodeInserted event

$('ul#mylist').on('DOMNodeInserted' ,function () {
    console.log('added an element');
});

If you are adding a li to ul and want to Listen to the event..

Check DEMO

like image 131
Sushanth -- Avatar answered Sep 21 '22 19:09

Sushanth --