Home > Web Front-end > JS Tutorial > Live() and die() have been removed from jquery, and the new version of event binding on() and off() methods is explained in detail

Live() and die() have been removed from jquery, and the new version of event binding on() and off() methods is explained in detail

黄舟
Release: 2017-06-26 09:48:25
Original
1691 people have browsed it

The following editor will bring you an articlejqueryRemoved live(), die(), new versionEventHow to bind on(), off() . The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

My balls hurt for almost 10 minutes. No matter how I called it, I got an error. After a final check, it turned out that jquery had removed the live() and die() methods. The new event binding method on() and the unbinding method off() are used.

Compared with live(), the new binding method on() is more efficient than the previous one. Because live() is fixed on the document node. If the bound elements are nested in a deep layer, the level-by-level delivery of events will definitely affect efficiency. On() is bound to the element selected by $(), and the nesting depth can be freely selected.

The parameters of on() on( events [, selector ] [, data ], handler(eventObject) )

The second parameter is optional and can be specified A bound element, for example:

$(".box").die().on('click','button',function(){});
Copy after login

In this way, it is bound to the button element in the .box element

You can bind multiple elements at the same time An event:

$(".demonstrate").on("mouseover mouseout","ul li",function(e){
if(e.type=="mouseover"){
$(this).addClass("over");
}else{
$(this).removeClass("over");
}
  })
Copy after login

on() can also receive an object parameter. The attribute of the object is the event type, and the attribute value is Event processingfunction:

The above is the detailed content of Live() and die() have been removed from jquery, and the new version of event binding on() and off() methods is explained in detail. For more information, please follow other related articles on the PHP Chinese website!

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