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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -