Append append element Binding event Invalid workaround

Source: Internet
Author: User

The problem is: with jquery append (or before, after, and so on) newly added elements of the page, the usual events can not be triggered, such as: Append the ID of the element ABC, then $ (#abc). Click (function () {}) is not effective.

1. Online said to use the live () function, the pro-test invalid, should be the version of jquery, anyway, so far is not used;

2. Workaround: Use the on function, to pay attention to the format (landlord engaged in a half-day, because the format is not right, hey, don't say ...) It's all tears)

          correct format:  $ (" Outerselector "). On (' EventType ', ' selector ', function () {});
          Outerselector is a DOM that always exists, selector is the node you want to listen to click,
example: $ (function () {
             $ ("form"). On (' click ', "[class= ' image ']", function () {
                 this.remove ();
            })
        })

Suddenly found all kinds of knowledge deep like the sea AH to study hard

Append append element Binding event Invalid workaround

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.