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 to this in multiple custom jQuery plugins, e.g.
this.live('click', function() {
...
});
the jQuery .live() doc has some guidance on how to migrate to .on() as follows:
$(selector).live(events, data, handler); // jQuery 1.3+
$(document).on(events, selector, data, handler); // jQuery 1.7+
however, this doesn’t work:
$(document).on('click', this, function() {
...
});
so… how do I make live events bound to this work with the new on() API?
Give this a shot:
A jQuery object has a
selectorproperty 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.