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

jquery1.10 method to bind events to new elements_jquery

WBOY
Release: 2016-05-16 16:56:32
Original
972 people have browsed it

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.
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