Better HN
topnewbestaskshowjobs
Log inSign up

webnoob

3 karma · joined Mar 7, 2025 (1y ago) · 1 submissions

Submissions

comment 1y ago · link · parent

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?