Why are jQuery Plugins not avialable to dynamically added elements thru ajax
I am using a jquery.messagebar plugin. What开发者_如何转开发 I am observing is that, the plugin is not available to the dynamically added elements loaded using ajax. Is this a normal behavior. If so what is a work around.
Plugins are available to such elements; of course they are. What you're seeing is that the plugin (like any other code) doesn't magically affect newly-created elements. The way most jQuery plugins work is by making changes, sometimes minor and sometimes not-so-minor, to the DOM based on elements selected by a jQuery selector.
One of the most common things to do in a callback function for the various jQuery ajax APIs is, in fact, to apply plugins as necessary to newly-loaded content.
There are non-standard events in some browsers regarding DOM updates, so it could be possible to rig some event-driven way of performing such work. Personally I don't see why that would be better than creating appropriate wrappers around the ajax APIs to do that as needed based on the needs of your own application.
精彩评论