jQuery: Can I automatically apply a plug-in to a dynamically added element?

前端 未结 4 1502
伪装坚强ぢ
伪装坚强ぢ 2021-01-21 02:33

I\'m in the process of converting my web app to a fully AJAX architecture.

I have my master page that is initially loaded and a div container that is loaded with dynamic

4条回答
  •  没有蜡笔的小新
    2021-01-21 02:49

    It seems incredibly wasteful to activate the plug-in every time an AJAX request completes. The plug-in only needs to be applied to the element once when it is first added to the DOM.

    You can get the best of both worlds here, for example:

    $("#something").load("url", function() {
      $(".entity-search-table", this).EntitySearch();
    });
    

    This way it's only applying the plugin to the .entity-search-table elements you just loaded, since we specified a context to $(selector, context) to limit it.

提交回复
热议问题