Wednesday, 7 August 2013

jQuery live to on, with $(this)

jQuery live to on, with $(this)

I'm updating my scripts so those are working in jQuery 1.9+
live is removed and I have to convert it to the on syntax. There are some
examples on the jQuery documentation. The documentation gives:
$(selector).live(events, data, handler); // jQuery 1.3+
$(document).on(events, selector, data, handler); // jQuery 1.7
So $("a").live("click", handler) schould be converted to
$(document).on("click","a", handler) and so on.
But how do I convert when I have no selector? In my case this is inside a
plugin.
$(this).live("click", handler)
This is not working:
$(document).on("click",$(this), handler)

No comments:

Post a Comment