News for hackers. Stuff that matters.
Re:HTML event handler attributes: down the rabbit hole by phillipseamore on Tuesday April 26, 2022 @04:53PM (#31173042)
I reach out for HTML events instead of addEventListener all the time. I get free event addition when dynamically adding content, also removal and tidying up after elements are removed - no memory leaks from unused event listeners. Plus it's obvious from browsing the code what different elements are hooked up to. I get called out on this often, but no one can argue with the ease of use and performance.
Re:HTML event handler attributes: down the rabbit hole by chris37879 on Tuesday April 26, 2022 @05:50PM (#31173618)
I prefer them too for the same reasons, they're even available with a really similar syntax in React's JSX extension: <button onClick={onClickHandler}>

I'm a big fan of the data attributes for the same reason, they bind onto the actual element they belong with, they're available in JS and CSS, and they add semantic meaning to your markup when you're reading the source.

Re:HTML event handler attributes: down the rabbit hole by asddubs on Tuesday April 26, 2022 @07:42PM (#31174548)
they're also much nicer for user-editable templates if you expect your users not to all be experts, or even if they are, have a full grasp of the system. they're right there where they're relevant, you see the element and right away you know that javascript will happen when you interact with it in certain ways