As far as I know, the click()
method isn't working for me because the element I'm clicking does not exist on page load (DOM ready).
I've found many answers suggesting to use .live('click',function(){...})
. This works great!
However, .live()
is depreciated as of jQuery 1.7
So, I've tried using .on('click',function(){...})
instead, but it doesn't not work (acts the same as .click()
.
Does anyone know why, or what I can do to use .on()
similarly to .live()
(which works) ?
Since on()
replaces both bind()
and live()
, you need to pass a third parameter in order to make use of event delegation (in other words, to make it work like the old live()
):
$('#container').on('click', '.element', function(){ });