JQuery _ jquery

Source: Internet
Author: User
This article mainly introduces jQuery's method of binding events to dynamically added elements. it compares the method of event binding in jQuery with the differences between common versions of jQuery and binding, and provides some reference value, for more information about how jQuery binds events to dynamically added elements, see the following example. Share it with you for your reference. The specific analysis is as follows:

Bind or click is generally used to bind events in jquery, but this can only be used to define events for elements that have been loaded. the elements that are subsequently inserted need to be bound separately. Use live before version 1.7. However, we recommend that you use on later than version 1.8. This section describes how to bind events to dynamically added elements in jQuery.
In actual development, a trigger event is bound to the dynamically generated html element.

For example

    To

      Dynamically added
    • Label add click event

      Previously, jquery 1.7 used live to dynamically bind events.

      $ ("# Testp ul li"). live ("click", function (){});

      Use on to dynamically bind events after jquery 1.7

      $ ("# Testp ul"). on ("click", "li", function () {// do something here });

      I hope this article will help you with jQuery programming.

    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.