0% found this document useful (0 votes)
2 views

JS7 ClassNotes

The document explains events in JavaScript, which indicate changes in the state of objects and can include mouse, keyboard, and form events. It covers event handling, the Event Object that provides details about events, and how to use event listeners to manage these events. Additionally, it includes a practice question about creating a toggle button for dark and light modes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JS7 ClassNotes

The document explains events in JavaScript, which indicate changes in the state of objects and can include mouse, keyboard, and form events. It covers event handling, the Event Object that provides details about events, and how to use event listeners to manage these events. Additionally, it includes a practice question about creating a toggle button for dark and light modes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Events in JS

The change in the state of an object is known as an Event

Events are fired to notify code of "interesting changes" that may affect code execution.

Mouse events (click, double click etc.)

Keyboard events (keypress, keyup, keydown)

Form events (submit etc.)

Print event & many more


Event Handling in JS

node.event = ( ) => {
//handle here
}

example
btn.onclick = ( ) => {
console.log(“btn was clicked”);
}
Event Object
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
}

e.target, e.type, e.clientX, e.clientY


Event Listeners

node.addEventListener( event, callback )

node.removeEventListener( event, callback )

*Note : the callback reference should be same to remove


Let‘s Practice
Qs. Create a toggle button that changes the screen to dark-mode when clicked & light-mode
when clicked again.

You might also like