#4074 closed defect (bug) (fixed)
jQuery and replacement of .on() for .live()
Reported by: | netweblogic | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | |
Component: | Core | Keywords: | |
Cc: | netweblogic |
Description
I know you're aware of this nuance, and that there already is compatibility with the depreciated function, but I think it's worth at least raising this so it gets done and avoid future issues.
You can get away with literally replacing .live(... with .on(... which works for me.
Alternatively, we should use the delegate() function, as that's not depreciated. Upside is it's more backwards compatible but not as simple to change.
Change History (5)
#2
@
13 years ago
yes, I'm very wrong actually! works first time round but not on following clicks. still easy to migrate, but a little more copy/paste involved:
$(selector).live(events, data, handler); jQuery 1.3+
$(document).on(events, selector, data, handler); jQuery 1.7+
as per http://api.jquery.com/live/
#3
@
13 years ago
I'd be happy to do this, but... some experience now from what I did in my plugin last week.
I would advise waiting until maybe even the next bump to a new jQuery version in WP. I've noticed a lot of users are getting js conflicts because themes and maybe even some plugins insist on using other jQuery libraries which are inevitably older than 1.7.
Since 1.7 still has backwards compatability with .live() I'd say it's not worth the headache, you'll have to do a lot less troubleshooting with users by doing this later.
The whole JavaScript file is long overdue for a rewrite/audit. If someone wants to provide a patch for the issue in this ticket, that would be great. I don't think this as simple as a find/replace because we have to change the syntax slightly for delegated events.