Solution to the failure of Jquery to bind Click event to newly inserted nodes

韦小宝
Release: 2017-11-29 10:48:40
Original
1700 people have browsed it

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

"

  • Link
  • " 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"); })
    Copy after login

    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!

    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 Recommendations
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!