Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistency with jquery event delegation #24

Closed
axten opened this issue May 22, 2019 · 1 comment
Closed

inconsistency with jquery event delegation #24

axten opened this issue May 22, 2019 · 1 comment

Comments

@axten
Copy link

axten commented May 22, 2019

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants