Jquery dynamic add element event invalidation solution


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:


$(".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);