TGViewer
Web Development - HTML, CSS & JavaScript Web Development - HTML, CSS & JavaScript @javascript_courses · 55.7K subscribers
Post #3534 2.08K
const input = document.querySelector("input");
input.addEventListener("keyup", () => {
console.log("Typing...");
});


🖱️ 13. Mouse Events

Common mouse events: click, dblclick, mouseover, mouseout, mousemove

Example:

button.addEventListener("mouseover", () => {
console.log("Mouse entered");
});


🚫 14. Prevent Default Behavior

Useful for forms and links.

form.addEventListener("submit", (event) => {
event.preventDefault();
console.log("Form Submitted");
});


🎯 15. Event Bubbling

When an event occurs, it moves from the child element to its parent.

Example:

parent.addEventListener("click", () => {
console.log("Parent");
});
child.addEventListener("click", () => {
console.log("Child");
});


Clicking the child prints:

Child

Parent

⚡ 16. Event Delegation

Instead of adding listeners to every child element, attach one listener to the parent.

document.getElementById("list")
.addEventListener("click", (event) => {
if(event.target.tagName === "LI") {
console.log(event.target.textContent);
}
});


Benefits

Better performance, Less memory usage, Works for dynamically created elements

🛠️ 17. Mini Project Example

Button Click Counter

let count = 0;
const button = document.querySelector("button");
button.addEventListener("click", () => {
count++;
button.textContent = count;
});


Every click increases the displayed count.

⭐ Most Important Interview Topics

DOM Basics, querySelector(), textContent vs innerHTML, classList, Event Listeners, Event Bubbling, Event Delegation, event.target, preventDefault()

📝 Practice Questions

Easy

Change heading text, Change background color, Hide and show a button

Medium

Build a counter, Create a to-do list, Toggle dark mode

Advanced

Form validation, Image slider, Dynamic table, Infinite scrolling

Double Tap ❤️ For More
  • ❤ 7
More from @javascript_courses
  1. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  2. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
  3. Oct 4, 2026DSA Handwritten Notes
  4. Sep 28, 2026To learn web design and development from basic to advanced levels, you can follow these st…
  5. Sep 27, 202610 Websites Every Developer & AI Enthusiast Should Bookmark ✅ roadmap.sh – Step-by-step le…
  6. Sep 26, 2026🔹 Escape Characters 2️⃣5️⃣ New Line You can use \n and \t: const message1 = "Hello\nWorld…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →