0

Js difference of events

Can someone explain the difference of how these events calling works, they're doing the same thing but the "onclick' one wasn't working in the electron js app Element.addEventListener('click', () =>{ // Some functionality }) Element.onclick = () => { // Some functionality }

24th Dec 2022, 4:05 AM
Tomoe
Tomoe - avatar
1 Respuesta
+ 1
They have the same functionality between these 2 functions. onclick event works on electron.js as well. Here an example: const { BrowserWindow } = require('electron') let win = new BrowserWindow({ width: 800, height: 600 }) let button = win.document.getElementById('my-button') button.onclick = () => { console.log('Button was clicked!') } However, it is generally considered to be best practice to use addEventListener rather than the on* properties when attaching event handlers in JavaScript. This is because addEventListener is more flexible and easier to work with, and also has better browser support.
24th Dec 2022, 4:30 AM
Calviղ
Calviղ - avatar