Home >Web Front-end >JS Tutorial >jquery1.10 method to bind events to new elements_jquery

jquery1.10 method to bind events to new elements_jquery

WBOY
WBOYOriginal
2016-05-16 16:56:32995browse

jquery1.10 removes the .live() method and adds a new .on() method to bind events to elements. The specific usage is as follows:

on(events,[selector],[data],fn )

Copy code The code is as follows:

$("#dataTable tbody tr").on ("click", function(event){
alert($(this).text());
});

The above method binds all tr The event is set, but the event cannot be bound to the newly added element.
Copy code The code is as follows:

$("#dataTable tbody").on(" click", "tr", function(event){
alert($(this).text());
});

The above method binds tbody An event is generated, and if the tr in it is a new element, the click event can be triggered uniformly.
Statement:
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