jQuery live alternative (is there only on()?)

189 Views Asked by At

I was using live() for using my function at the ajax datas.

just like: $(".mydiv").live('click', function(){ alert("blablabla"); })

It was working fine, if I click on ajax datas which is '.mydiv'

but 'on' method doesn't support this?

$(".removebet").on('click',' i', function(){alert("blablabla");});

It doesn't work, if "i" is come from ajax datas. Why? How can I solve this?

1

There are 1 best solutions below

1
On

The selector for the elements that you want to bind using .on needs to exist when .on is called. That is to say that if .removebet does not exist when .on is called (it sounds like it doesn't), .on won't bind to anything.

Your safest bet would be to use

$(document).on("click", ".removebet i" ...

Ideally pick an existing selector that is closer to the target descendants than document.