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 }
1 Answer
+ 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.