setun-90 Posted June 14, 2016 Share Posted June 14, 2016 After reading about things such as event.currentTarget and a discussion with Ingolme, I'm now having serious doubts about my understanding of DOM. My basic question is: are DOM event handlers called synchronously or asynchronously? Link to comment Share on other sites More sharing options...
Ingolme Posted June 14, 2016 Share Posted June 14, 2016 You were right in your previous post that your code behaved differently than it would all in a single function. I had not noticed at first that the set() function was being called once for each level of nesting as opposed to only once for each click event. event.currentTarget is a reference to the actual element that the event listener was attached to, as opposed to event.target, which is a reference to the lowest leaf node that was actually clicked on. Events are asynchronous, they don't run along with the rest of the code on the page, only when an event is fired. Link to comment Share on other sites More sharing options...
setun-90 Posted June 15, 2016 Author Share Posted June 15, 2016 Right, so would it be possible to write a function in the linked script that could 'see' event.currentTarget change, either across function calls or within a call? Cause then I wouldn't need to attach handlers or listeners to any descendant of #nav. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 15, 2016 Share Posted June 15, 2016 The event object only gets passed to an event handler. But you could put an event handler on the parent, and then use currentTarget (or target) to see which element actually fired the event. Look into event bubbling versus capturing. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now