nolimits4web / dom7

Minimalistic JavaScript library for DOM manipulation, with a jQuery-compatible API
http://framework7.io/docs/dom7.html
MIT License
162 stars 45 forks source link

inconsistency with jquery event delegation #24

Closed axten closed 5 years ago

axten commented 5 years ago

Hi, i'm currently migrating from jQuery to dom7, so thanks for that small library :) Now I have a problem with event delegation.

Example:

// html
<nav class="menu">
     <div data-action="action1">Test1</div>
     <div data-action="action2"><button>Test2</button></div>
</nav>

// JS
$$('.menu').on('click', '[data-action]', (event) => {
    const action = $$(event.currentTarget).attr('data-action');
    // do somethin with action
});

this is working with jQuery, because event.currentTarget is the delegated element. But in dom7 this is always the parent element (menu). So this example is not working with dom7 when clicking the data-action elements.

nolimits4web commented 5 years ago

Use this inside event handler, it will point to element that receives event. currentTarget will not be added to Dom7