I'm used to using .click()
and delegate('click')
, so when I read both were deprecated in recent versions of jQuery I thought I'd read up on it, but I'm scratching my head a bit.
The documentation here seems to suggest that this is a drop-in replacement for .live() and .delegate(), but .click() and .bind() had a different behavior, namely binding to currently existing objects, where the others bound to any objects that matched the selector pattern througout the lifespan of the DOM.
In most cases, this wouldn't make a big difference, but when adding elements to your DOM dynamically, this is an important distinction. New objects matching the old pattern would not have listeners tied to the click
event using .click()
, but would with .delegate()
.
My question is, how does one use the .on()
method to duplicate the behavior of both the pre-existing .delegate()
and .bind()
? Or is everything in the future going towards the .delegate()
style?