Let’s take a look atJqueryBind the Clickevent to the newly inserted nodeThe solution to the failure, let’s learn how to solve itjQueryHow to bind click invalidation and strengthen your understanding ofjQuery!
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 isstatic, which means it was not added dynamically later.
Then I dynamically added something like
"
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 toPHP 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!