
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
jquery.initialize
Advanced tools
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
Another note (bezborodow). The Web
Components
suite is now widely adopted natively by most modern browsers as a standardised
feature such that it can now be used efficiently (without the overhead of
MutationObserver)
to achieve the same objectives as this library originally intended to
facilitate. —2023-05-27
jQuery.initialize plugin is created to help maintain dynamically created
elements on the page.
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.
Simple demo - click here
$.initialize(".some-element", function() {
$(this).css("color", "blue");
});
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!
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();
targetBy 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:
$.initialize(".some-element", function() {
$(this).css("color", "blue");
}, { target: document.getElementById('observe-this-element') });
Otherwise, target will default to document.documentElement.
observerA custom
MutationObserverInit
may be provided. If not provided, it will default to internal configuration.
Plugin is based on MutationObserver. It will works on IE9+ (read note
below) and every modern browser.
Note: To make it work on IE9 and IE10 you'll need to add MutationObserver polyfill - like ones here: https://github.com/webcomponents/webcomponentsjs
Performance test (thanks to @bezborodow and @liuhongbo)
bower and npm compatible, add advanced performance test.FAQs
jQuery plugin for dynamically created elements initialization
The npm package jquery.initialize receives a total of 169 weekly downloads. As such, jquery.initialize popularity was classified as not popular.
We found that jquery.initialize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.