How do I resolve an event's binding problem after jquery append new elements to the page?

Source: Internet
Author: User

Today there is a get to a new point of knowledge, that is, when we add new elements to the page, the pre-load function method is invalid for the new element, let me say how to solve this problem?

I first look at the JQ API documentation did not find the method, no result had to find some information on the Internet, sure enough to find the live method.

It's actually very simple:

  

1. This is the project required to achieve the effect, when I do not use the live event, only with the simple hover event: The hover event is not loaded in, there is no border effect I want, as follows

/* Add style via user skill tag */
$ (function () {

$ (". s-edited"). Hover (function () {  

$ (this). Toggleclass ("Borderd");

})

})

2. When I use live, the effect is achieved, such as:

   

The code is as follows:

/* Add style via user skill tag */
$ (". s-edited"). Live ("hover", function () {
$ (this). Toggleclass ("Borderd");
})

I took a closer look at the introduction of live,

A matching element binds an event handler function (such as the hover event). Custom events can also be bound.
    
PS: I am a novice rookie, big God do not spray!

How do I resolve an event's binding problem after jquery append new elements to the page?

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.