You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note from author (pie6k). I've created this lib few years ago and it was nice
back then. Now you should probably not be using jQuery for things like that and
go with React or something similar. Thank you.
—2018-11-21
Bug reports are still accepted.
jQuery.initialize
jQuery.initialize plugin is created to help maintain dynamically created
elements on the page.
Synopsis
jQuery.initialize will iterate over each element that matches the selector and
apply the callback function. It will then listen for any changes to the
Document Object Model
and apply the callback function to any new elements inserted into to the
document that match the original selector.
$.initialize([selector], [callback]);
This allows developers to define an initialisation callback that is applied
whenever a new element matching the selector is inserted into the DOM. It works
for elements loaded via AJAX also.
But now if new element matching .some-element selector will appear on page,
it will be instantly initialised. The way new item is added is not important,
you do not need to care about any callbacks etc.
$("<div/>").addClass("some-element").appendTo("body"); //new element will have blue color!
Unobserving
To cease observation of the document, you may disconnect the observer by
calling disconnect() on the returned
MutationObserver
instance which stops it from receiving further notifications until and unless
observe() is called again. . E.g.,
var obs = $.initialize([selector], [callback]); // Returns MutationObserver
obs.disconnect();
Options
target
By default, the entire document is observed for changes. This may result in
poor performance. A specific node in the DOM can be observed by specifying a
target: