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

jquery dynamically added element event failure solution_jquery

WBOY
Release: 2016-05-16 16:47:11
Original
1632 people have browsed it

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);
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template