How to translate jQuery .live() to .on() with events bound to this?

前端 未结 4 883
一向
一向 2021-02-13 04:11

I\'m in the process of converting code from the deprecated .live() API to .on() (see the jQuery 1.7 release notes)

I have live events attached

4条回答
  •  死守一世寂寞
    2021-02-13 04:41

    Give this a shot:

    $(document).on('click', this.selector, handler);
    

    A jQuery object has a selector property that represents the selector used to create that object.

    Note that the selector is modified with traversal methods, so I would assume that your plugin is generally used upon initial DOM selection.


    To avoid using an internal property, you could simply change the API of your plugin to require a selector to be passed explicitly.

提交回复
热议问题