📲 Download Utility Tools Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

8️⃣ JavaScript Events

JavaScript events allow you to make your website interactive.
An event happens when a user does something like clicking, typing, or submitting a form.

👉 Example:

  • Click → event
  • Typing → event
  • Hover → event

🖱️ 1. Mouse Events

These events happen when the user uses the mouse.

Common Mouse Events:

  • click → when button is clicked
  • dblclick → double click
  • mouseover → when mouse enters element
  • mouseout → when mouse leaves element

Example:

<button onclick="showMessage()">Click Me</button><script>
function showMessage() {
alert("Button clicked!");
}
</script>

⌨️ 2. Keyboard Events

These events happen when user types on keyboard.

Common Keyboard Events:

  • keydown → key pressed
  • keyup → key released
  • keypress (old, avoid now)

Example:

<input type="text" onkeyup="checkInput()"><script>
function checkInput() {
console.log("User is typing...");
}
</script>

📝 3. Form Events

These events are used in forms.

Common Form Events:

  • submit → when form is submitted
  • change → when input value changes
  • focus → when input is selected
  • blur → when input loses focus

Example:

<form onsubmit="handleSubmit(event)">
<input type="text" required>
<button type="submit">Submit</button>
</form><script>
function handleSubmit(e) {
e.preventDefault(); // stop page reload
alert("Form submitted!");
}
</script>

🔄 4. Event Bubbling

Event bubbling means:

👉 Event starts from child element → goes up to parent

Example:

<div onclick="parentClick()" style="padding:20px; background:lightblue;">
<button onclick="childClick()">Click Me</button>
</div><script>
function parentClick() {
alert("Parent clicked");
}function childClick() {
alert("Button clicked");
}
</script>

👉 When you click button:

  1. Button event runs
  2. Then parent event runs

Stop Bubbling:

function childClick(event) {
event.stopPropagation();
alert("Only button clicked");
}

🎯 5. Event Delegation

Event delegation means:

👉 Instead of adding events to many elements,
you add one event to parent

Why use it?

  • Better performance
  • Works for dynamic elements

Example:

<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul><script>
document.getElementById("list").addEventListener("click", function(e) {
if (e.target.tagName === "LI") {
alert(e.target.innerText);
}
});
</script>

👉 One event handles all <li> items


🧪 Practice Tasks

✅ 1. Interactive Button

<button id="btn">Click Me</button><script>
document.getElementById("btn").addEventListener("click", function() {
this.innerText = "Clicked!";
});
</script>

✅ 2. Keyboard Typing Detector

<input type="text" id="inputBox" placeholder="Type something"><p id="output"></p><script>
document.getElementById("inputBox").addEventListener("keyup", function(e) {
document.getElementById("output").innerText =
"You typed: " + e.target.value;
});
</script>

💡 Pro Tips (Important for Interviews)

  • Use addEventListener() instead of inline events
  • Use event object (e) for advanced control
  • Avoid keypress (deprecated)
  • Use event delegation in dynamic apps (like lists, tables)


AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes