Resolves the binding issue of the event after jquery append a new element to the page _jquery

Source: Internet
Author: User

I first see the JQ API documents did not find a way, no results have to find some information on the Internet, sure enough to find a live method.

It's actually very simple:

1. This is the effect of the project requirements, when I did not use the live event, only a simple hover event: The hover event did not load in, no I want the border effect, the effect is as follows

Copy Code code as follows:

* * Through the user skills tag to increase the style * *
$ (function () {
$ (". s-edited"). Hover (function () {
$ (this). Toggleclass ("Borderd");
})
})

2. When I used live, the effect reached, the following figure:

The code is as follows:

Copy Code code as follows:

* * Through the user skills tag to increase the style * *
$ (". s-edited"). Live ("hover", function () {
$ (this). Toggleclass ("Borderd");
})

I took a close look at the introduction to live,

Bind an event handler function (such as a hover event) to all current and future elements that will match. Custom events can also be bound.

PS: I am a novice rookie, big God not to spray!

The above is the entire content of this article, I hope you can enjoy.

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.