I am trying to understand this particular difference between the direct and delegated event handlers using the jQuery .on() method. Specifically, the last
Tangential to the OP, but the concept that helped me unravel confusion with this feature is that the bound elements must be parents of the selected elements.
.on
. .on()
.Delegation does not work like .find(), selecting a subset of the bound elements. The selector only applies to strict child elements.
$("span.green").on("click", ...
is very different from
$("span").on("click", ".green", ...
In particular, to gain the advantages @N3dst4 hints at with "elements that are created in future" the bound element must be a permanent parent. Then the selected children can come and go.
EDIT
.on
doesn't workTricky reasons why $('.bound').on('event', '.selected', some_function)
may not work:
.on()
.stopPropagation()
.(Omitting less tricky reasons, such as a misspelled selector.)