Home  >  Article  >  Web Front-end  >  jquery dynamically added element event failure solution_jquery

jquery dynamically added element event failure solution_jquery

WBOY
WBOYOriginal
2016-05-16 16:47:111628browse

Today I encountered a problem when writing JQUERY: when using a script to dynamically add element xxx, the event $(".x .y").click(function)... failed.

I just found the live function online. The method is as follows:

Event binding: $(".x .y").click(function) needs to be changed to:

Copy code The code is as follows:

$(".x .y").live('click', function);

However, since the live method is no longer supported after version 1.8, you need to use the following on method in jquery to solve the problem of dynamically adding elements in scripts:
Copy code The code is as follows:

$(".y").on('click','.x',function);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn