JavaScript Lecture 7 Notes
The change in the state of an object is known as an Event.
Events are fired to notify code of "interesting changes".
Event handling is used to perform actions when an event occurs.
node.event = () => {
//handle here
}
btn.onclick = () => {
console.log("btn was clicked");
}
Event Handling in JS
It is a special object that has details about the event.
All event handlers have access to the Event Object's properties and methods.
node.event = (e) => {
//handle here
}
Event listeners are used to attach multiple event handlers.
node.addEventListener( event, callback ) node.removeEventListener( event, callback )
Note: callback reference same होना चाहिए remove के लिए
Event ListenersQs. Create a toggle button for dark/light mode.
Solution