Quick one: event handling bug here.
const button = document.querySelector('#save');
button.addEventListener('click', saveForm());
function saveForm() {
console.log('saved');
}
Reply with what is broken and how you would fix it.
Quick one: event handling bug here.
const button = document.querySelector('#save');
button.addEventListener('click', saveForm());
function saveForm() {
console.log('saved');
}
Reply with what is broken and how you would fix it.
You’re calling saveForm() immediately and passing its return value to addEventListener, so nothing runs on click. Pass the function reference instead: button. addEventListener('click', saveForm) (or () => saveForm()).
You’re calling saveForm() immediately and passing its return value to addEventListener, so nothing runs on click. Pass the function reference instead: button. addEventListener('click', saveForm) (or () => saveForm() if you need to pass args).
:: Copyright KIRUPA 2024 //--