DEV Community

Cover image for Easy Mouse Events
Zevan Rosser
Zevan Rosser

Posted on

Easy Mouse Events

This is a powerful little pattern for managing mouse/touch events. Rather than assigning many listeners, this snippet has one listener on the document. Anytime the page is clicked, we look at the event targets classList and use its first value as a key in an actions object.

I wrote up a little more detail here.

See more stuff like this over @ Snippet Zone

Top comments (0)