DEV Community

Discussion on: A Detailed Breakdown of HTML Form Event Attributes

Collapse
 
lexlohr profile image
Alex Lohr

You shouldn't use the DOM level 1 event attributes (on...) anymore, but instead use the recent UI Events (node.addEventListener('...', (ev) => {})). Only if you're using a framework like React or Vue, then what looks like event attributes is already translated into internal handling of UI Events.

Collapse
 
monfernape profile image
Usman Khalil

What problems do we face using events with 'on' prefix?

Collapse
 
lexlohr profile image
Alex Lohr

You cannot have multiple events then. If you set the DOM level 1 event after a UI Event, the latter will be overwritten. You don't get access to the event object. Finally, you either need to add JS code directly to the HTML or have global variables lying around, which is a bad idea either way.

Collapse
 
desoga profile image
deji adesoga

Thank you for pointing that out. Helps put everything in perspective.