Jquery dynamic generation of element mouse response method live () function

Source: Internet
Author: User

The simplest method

When you click the button, the p element is hidden or displayed:

The code is as follows: Copy code
$ ("Button"). live ("click", function (){
$ ("P"). slideToggle ();
});

After jQuery dynamically generates an HTML element, if there is a mouse CLICK event in the element set.

In this case, the. live () method is used to make the generated dynamic elements remain effective after the page is loaded, so that the mouse click event takes effect.

The code is as follows: Copy code

JQuery (document). ready (function (){
Var contentTR = $ ('. info tr: eq(0w.'{.html ();
Var e = 0;
$ ('. Addrow'). click (function (){
E = e + 1;
 
$ (". Info. addrow"). parent (). parent (). before ('<tr>' + contentTR + '</tr> ');
$ (". Info tr: eq ("+ e + ")"). find ("input: eq (0 )"). attr ("name", "a" + e );
$ (". Info tr: eq ("+ e + ")"). find ("input: eq (1 )"). attr ("name", "B" + e );
$ (". Info tr: eq ("+ e + ")"). find ("select: eq (0 )"). attr ("name", "c" + e );
$ (". Info tr: eq ("+ e + ")"). find ("input: eq (2 )"). attr ("name", "d" + e );
$ (". Info tr: eq ("+ e + ")"). find ("input: eq (3 )"). attr ("name", "f" + e );
 
});
$ ('. Del'). live ('click', function (){
$ (This). parent (). parent (). remove ();
});
});

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.