The jquery click event fails because live is no longer recommended after JQUERY1.7. The solution is to change the code to "$("#a").on('click',function() {for(var i=0 ; i
## Recommended: "jquery video tutorial"
Put the complete code first
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>测试</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script> <style type="text/css"> #a{ width:50px; height:50px; background: rgb(54, 54, 54); } #b{ width:50px; height:50px; background: rgb(144, 243, 182); } #d{ width:50px; height:50px; background: rgb(114, 116, 231); } li{ list-style: none; } .display{display:block;} .hide{display:none;} </style> </head> <body> <p id="a"></p> <p id="b"></p> <p id="d"></p> <p id="c"> <ul> <li id="c1">11111111</li> <li id="c2">22222222</li> <li id="c3">33333333</li> </ul> </p> <script type="text/javascript"> var link = $('ul li'); var leng = c.querySelectorAll("li").length; $("#a").on('click',function(){ for(var i=0 ; i< leng;i++){ link[i].className = 'display' } }) $("#b").on('click',function(){ for(var i=0 ; i< leng;i++){ if(link[i].id !== 'c2'){ link[i].className = 'hide' }else{ link[i].className = 'display' } } }) $("#d").on('click',function(){ for(var i=0 ; i< leng;i++){ if(link[i].id !== 'c1'){ link[i].className = 'hide' }else{ link[i].className = 'display' } } }) </script> </body> </html>
At first the click event was written like this, but it was found that the click was invalid. The ones that support binding events to dynamic elements and attributes are live and on, among which live is not recommended after JQUERY 1.7. Now we mainly use on. When using on, we should also pay attention to it. The elements before on must also exist in the dom when the page is loaded. Dynamic elements or styles can be placed in the second parameter of on.
$('#a').click = function(){ for(var i=0 ; i< leng;i++){ link[i].className = 'display' } }
Later, just change the code to the following code
$("#a").on('click',function(){ for(var i=0 ; i< leng;i++){ link[i].className = 'display' } })
The above is the detailed content of What to do if jquery click event fails. For more information, please follow other related articles on the PHP Chinese website!

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools
