HNHacker News
TopNewBestAskShowJobs

webnoob

3 karma · joined March 7, 2025

submissionscomments
webnoob··on Introducing command And commandfor In HTML
I'm curious, as a noob in web programming. That first example does

    document.addEventListener('click', ...
Instead of

    someButton.addEventListener('click', ...
And in fact, all the framework example show button onClick not document onClick

I know some situations where adding the event listener to the document is correct but I've never seen it in this button type situation.

Is that pattern for buttons common? What does it solve?