开发者

Why are jQuery Plugins not avialable to dynamically added elements thru ajax

开发者 https://www.devze.com 2023-03-13 11:15 出处:网络
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 w

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消