Home > Web Front-end > JS Tutorial > body text

Solve the binding problem of events after Jquery appends new elements to the page_jquery

WBOY
Release: 2016-05-16 16:09:16
Original
933 people have browsed it

I first looked at the jq api documentation but couldn't find a method. To no avail, I had to look for some information online, and sure enough I found a live method.

It’s actually very simple:

1. This is the effect required by the project. When I did not use the live event and only used a simple hover event: the hover event was not loaded and there was no border effect I wanted. The rendering is as follows

Copy code The code is as follows:

/*Add styles through user skill tags*/
  $(function(){  
   $(".s-edited").hover(function(){ 
​​​​​$(this).toggleClass("borderd");
   })
  }) 

2. After I used live, the effect was achieved, as shown below:

The code is as follows:

Copy code The code is as follows:

/*Add styles through user skill tags*/
  $(".s-edited").live("hover",function(){
   $(this).toggleClass("borderd");
  })

I carefully read the introduction about live,

Bind an event handler (such as hover event) to all current and future matching elements. Custom events can also be bound.

PS: I am a newbie, please don’t criticize!

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!