Events in JavaScript for beginners ⚡⚡

A Thread🧵👇🏻

Events in JavaScript for beginners ⚡⚡ A Thread🧵👇🏻

·

2 min read

🎯 Events in JavaScript :-

⇨ JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page.

⇨ When the page loads, it is called an event. When the user clicks a button, that click too is an event. Other examples include events like pressing any key, closing a window, resizing a window, etc.

🎯How To Add Event in JavaScript?

⇨ Javascript events apply to the HTML elements,

e.g- we can add an event to a button.

this is how we can add:

here event is the event handler and doSomething is executed when calling an event

🢖 A click is an event.

🢖 on click is an event handler e.g: click means when a user clicks. what will happen?

🢖 The code in "double quotations is js code which will be executed".

❍ All Events in Javascript

⇨ Click - Execute code on click

⇨ Double Click - Execute code on Double click

⇨ Right Click - Execute code on Right click

⇨ Mouse Hover - Execute code on Hovering

⇨ Mouse Out - Execute code on mouse leaving

⇨ Mouse Down - Execute code on pressing mouse button

⇨ Mouse Up - Execute code on releasing mouse button

⇨ Key Press - Execute code on pressing any key

⇨ Key Up - Execute code on releasing the key

⇨ Load - Execute code on page load

⇨ Un Load - Execute code on page reload or closing

⇨ Resize - Execute code on window resizing.

⇨ Scroll - Execute code on scrolling

⛔Note: You Must have to add "on", before every event.

🎯How to use Events in best way?

⇨ Make a function of all the code you want to be executed when a specific event calls and pass that function to the event handl

**Example:

function myFunction() { alert("Your Page is loaded"); }

⇨ function will be called on page

**

I hope this thread was helpful to you if you like it drop your comments

Did you find this article valuable?

Support ramu k by becoming a sponsor. Any amount is appreciated!