As mentioned above: you can use mutation events. But these events have some limitations: there is no support for IE prior to version 9, and there are some performance problems with these events. In your case, you should listen to DOMNodeInserted . Possible example:
document.addEventListener("DOMNodeInserted", function(event){ var target = event.srcElement || event.target; if (target && target.tagName.toLowerCase() == 'input') {
I would prefer a little easier in your case: put your initialization logic in a separate function and call this function each time after manipulating the DOM. Inside this function, add the value of the class or data to each initialized element and verify that this class is initialized only once:
function init() { $('.input_box').not('.initialized').each( function() { var ac = $(this).addClass('initialized').autocomplete(acOptions); }); }
source share