简体   繁体   中英

How do I apply jquery plugin to newly created element

I have a third party function that I use. To use ii I just run:

$('.myElements').thirdPartyFunction(options);

It works fine. However if I dynamically add an element with class .myElements , how can I have it run the thirdPartyFunction on that that element?

If you're not worried about performance you can use DOMNodeInserted

$(document).bind("DOMNodeInserted"), function(event){
      $(event.target).find(".myElements").addBack(".myElements").thirdPartyFunction();
}

Though it is not very performant, so you may wish to look at something else.

Other options: Alternative to DOMNodeInserted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM