4 ms·
A crash course in how DOM events work
- rriepe 16y agoI feel like, now that the magic trick has been explained, my world is slightly less full of wonder and excitement. Thanks, I think.
- JoeAltmaier 16y agoThe first time I finished reading through the complete source of an operating system, I felt the same way: "Wait, where was the magic? Did I miss it?"
- panic 16y agoI bet we're going to feel the same way when we figure out how our brain works.
- billybob 16y agoFunny, whenever I first understand something mysterious like that, I feel more hopeful and confident. If it's magic, how can I trust it? What do I do if it doesn't behave as expected? If I understand it, I can face it. I can figure out problems. I can find creative approaches. It isn't magic, so I don't have to be afraid. I think that's a good feeling.
- warfangle 16y agoWhile this is intended to be a crash course, I do want to note that event listeners don't quite get called like that. The event bubbling and capturing is quite accurate, but there are some specific differences in how listeners on any given element's event are called when compared to simply looping through and executing them: The order in which they are called is not determinate. All of them will be called, but you cannot rely on the order in which they are called. Throwing an exception will also not prevent other event listeners from executing. See: http://ajaxian.com/archives/the-differences-between-callbacks-and-events http://ajaxian.com/archives/the-differences-between-callback...