Jquery dynamic add element event invalidation solution
- 2020-03-30 03:03:49
- OfStack
Today I had a problem writing JQUERY: when using a script to dynamically add the element XXX, the event $(".x.y ").click(function)... Failure problem.
Just started to find online with live function, the method is as follows:
Event binding: $(".x.y ").click(function) needs to be changed to:
However, since the live method is no longer supported after version 1.8, the following jquery on method is needed to dynamically add elements:
Just started to find online with live function, the method is as follows:
Event binding: $(".x.y ").click(function) needs to be changed to:
$(".x .y").live('click',function);
However, since the live method is no longer supported after version 1.8, the following jquery on method is needed to dynamically add elements:
$(".y").on('click','.x',function);