Home > Article > Web Front-end > Live() and die() have been removed from jquery, and the new version of event binding on() and off() methods is explained in detail
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(){});
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"); } })
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!