The Greatest Candy and Event Delegation

2023-11-06


Hey Folks,

It was a good spooky candy week, but let me submit to you, dear reader, that the greatest of all candies is largely absent from this week's candy hauls:

A single caramel cream in a wrapper with a deliciously chewy caramel exterior and a sweet cream interior...

That's right. The humble Caramel Cream. Perfected over 100 years ago and still delivering today. I recommend you try it if you've never had one.


Thinking Too Hard

I had an issue this week where I have two technologies that don't talk to each other. My coworker suggested a technique I had seen before but never knew the name of. It's ... whispersevent delegation ✨. Because the event bubbles up the DOM to the document object, it doesn't matter whether one system knows about the other or not ... The DOM knows!

This is also great for closing patterns, like closing a dropdown if you click outside of it. You just invert it, instead of looking for that particular element in the event.target you check to see if it's NOT there. The matches() and closest() methods work really well here.


Interesting Web Bits


Don't miss what's next. Subscribe to Net Noodlings with Nathan: