Home > Article > Web Front-end > Solution to the failure of Jquery to bind Click event to newly inserted nodes
Let’s take a look atJqueryBind the Click event to the newly inserted nodeThe solution to the failure, let’s learn how to solve itjQueryHow to bind click invalidation and strengthen your understanding of jQuery!
1. Some people say to use Live. In fact, the latest Jquery no longer supports Live. The solution to live is as follows:
You can watch this or not, just be aware of it. The following describes the ON method.
live: Introduction to the use of Live
2. Some people have used ON to solve the problem. This solution is basically reasonable.
On: On’s introduction can solve the problem
On’s method can basically solve the problem, but you should also make a choice based on your specific situation. Not everyone's code is as simple as the case above. But it never changes from its roots.
This is what I did and finally solved the problem.
I have a UL tag that is static, which means it was not added dynamically later.
Then I dynamically added something like
"25edfb22a4f469ecb59f1190150159c6e689c7a8aee9d1d2cbf52f807582ec41Link5db79b134e9f6b82c0b36e0489ee08edbed06894275b65c1ab86501b08a632eb" content.
I made my choice according to the following method.
$("#subul").on('click','li>a', function (e) { //取消冒泡 //var e = e || window.event; // e.stopPropagation(); alert("asssss"); var areaid = this.attributes.getNamedItem("id").nodeValue; alert(areaid); $("#subul>li>a").removeClass("smallBtSelected"); $("#" + areaid).addClass("smallBtSelected"); })
The above is all the content of Jquery’s solution to the failure of binding Click event to newly inserted nodes. For more information, please go to PHP Chinese websitesearch!
Related recommendations:
jQuery implements the method of finding the nearest parent node
How jQuery gets the browser type and version number
10 jQuery code snippets for efficient web development
The above is the detailed content of Solution to the failure of Jquery to bind Click event to newly inserted nodes. For more information, please follow other related articles on the PHP Chinese website!