𝟮𝟮 𝗗𝗮𝘆𝘀 𝗼𝗳 𝗠𝗘𝗥𝗡 𝗦𝘁𝗮𝗰𝗸 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴
I studied JavaScript events on Day 22.
Events make a page react when you interact with it. A click or a hover is an event.
Two ways exist to handle these signals:
- Inline handlers: You write code inside HTML. This mixes logic with structure. It makes HTML messy.
- Script handlers: You use a separate file. This is the professional way.
You select the element in your script. You assign a function to it.
let btn = document.querySelector("#myBtn"); btn.onclick = () => { console.log("Button clicked!"); };
Source: https://dev.to/ali_hamza_589ec7b3eb6688d/22-day-of-learning-mern-stack-2eb4