jquery - Making .on() handler react only to element's own event -
is there more elegant way avoid reacting bubbling events descendants this:
$('#element').on('click', function (e) { if (e.target != this) return; alert("it's a-me!"); });
(jsfiddle).
maybe parameter .on() or other method i'm missing?
no, that's pretty elegant way handle it.
the other way requires bind events on child elements , stoppropagation there, however, mean child elements need know parent element may or may not related. better keep within single event, have least impact on rest of page/application.
another reason why best way handle won't break events being delegated said child elements.
Comments
Post a Comment