jQuery .delegate()
Learn all about the jQuery function .delegate().
As of jQuery 1.7, .delegate()
has been superseded by the .on() method. For earlier versions, however, it remains the most effective means to use event delegation. More information on event binding and delegation is in the .on() method. In general, these are the equivalent templates for the two methods:
1
2
3
4
|
|
For example, the following .delegate()
code:
1
2
3
|
|
is equivalent to the following code written using .on()
:
1
2
3
|
|
To remove events attached with delegate()
, see the .undelegate() method.
Passing and handling event data works the same way as it does for .on()
.