Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Understanding Events in JavaScript (Beginner Friendly Guide)

Modern websites are interactive. When you click a button, type in a search box, or submit a form, something happens. This behavior is possible because of JavaScript Events. In this blog, we will learn: Introduction to Events How Events…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Modern websites are interactive. When you click a button, type in a search box, or submit a form, something happens.



This behavior is possible because of JavaScript Events.



In this blog, we will learn:




  1. Introduction to Events

  2. How Events Work

  3. Common Event Types

  4. The Event Object

  5. Event Propagation

  6. Event Delegation

  7. Removing Event Listeners



Let’s start.



1. Introduction to Events



An event is an action that happens in the browser.



Events can be triggered by:




  • User actions

  • Browser actions



Examples of events
































Action Event
Clicking a button click
Typing in keyboard keydown
Submitting a form submit
Moving mouse over element mouseover
Page loaded load


Example




<button id="btn">Click Me</button>









document.getElementById("btn").addEventListener("click", function(){
alert("Button clicked!");
});






Output



When the user clicks the button, an alert message appears.



This is called interactivity.



Without events, websites would be static like a newspaper page.



2. How Events Work



JavaScript uses an event-driven model.



This means the browser waits for events and then runs code.



The process




  1. User performs an action

  2. Browser detects the event

  3. JavaScript runs the event handler



Syntax of addEventListener




element.addEventListener("event", function)






Example




<button id="btn">Click</button>









let btn = document.getElementById("btn");

btn.addEventListener("click", function(){
console.log("Button was clicked");
});






Output




Button was clicked






This message appears in the console when the button is clicked.



3. Common Event Types



JavaScript has many event types.



1. Mouse Events

Triggered by mouse actions.




























Event Description
click user clicks
dblclick double click
mouseover mouse enters element
mouseout mouse leaves element


Example




<div id="box">Hover over me</div>









let box = document.getElementById("box");

box.addEventListener("mouseover", function(){
box.style.background = "yellow";
});

box.addEventListener("mouseout", function(){
box.style.background = "white";
});






Output

When the mouse enters the box → yellow background

When the mouse leaves → white background



2. Keyboard Events



Triggered when keys are pressed.
























Event Description
keydown key pressed
keyup key released
keypress key pressed (older event)


Example




<input type="text" id="inputBox">









let input = document.getElementById("inputBox");

input.addEventListener("keydown", function(event){
console.log("Key pressed:", event.key);
});






Output



Typing A B C



Console shows




Key pressed: A
Key pressed: B
Key pressed: C






3. Form Events



Used when working with forms.
































Event Description
submit form submitted
change value changed
input typing
focus field selected
blur field left


Example




<form id="form">
<input type="text">
<button>Submit</button>
</form>









let form = document.getElementById("form");

form.addEventListener("submit", function(event){
event.preventDefault();
alert("Form submitted!");
});






Output

The alert appears without refreshing the page.



4. Window / Document Events



These events happen on the browser window.




























Event Description
load page fully loaded
DOMContentLoaded HTML loaded
resize window resized
scroll page scrolled


Example




window.addEventListener("scroll", function(){
console.log("User is scrolling");
});






4. The Event Object



Whenever an event occurs, JavaScript creates an event object.



This object contains information about the event.



Example




document.addEventListener("click", function(event){
console.log(event.target);
});






Important Properties
































Property Meaning
event.target element clicked
event.type type of event
event.key key pressed
event.clientX mouse X position
event.clientY mouse Y position


Example




document.addEventListener("click", function(event){
console.log("Clicked element:", event.target);
console.log("Event type:", event.type);
});






Prevent Default Behaviour



Some elements have default actions.



Example:




  • Form reload

  • Link navigation



We can stop it using:




event.preventDefault()






Example




<a href="https://google.com" id="link">Go to Google</a>









document.getElementById("link").addEventListener("click", function(event){
event.preventDefault();
alert("Link prevented!");
});







5. Event Propagation [To Be Discussed]



When an event happens inside nested elements, it travels through the DOM.



This is called event propagation.



There are two phases:



1. Event Bubbling



Event goes from child → parent → document



Example:




<div id="parent">
<button id="child">Click</button>
</div>









document.getElementById("child").addEventListener("click", function(){
console.log("Child clicked");
});

document.getElementById("parent").addEventListener("click", function(){
console.log("Parent clicked");
});






Output




Child clicked
Parent clicked







Because event bubbles up.



2. Event Capturing



Event goes from parent → child




addEventListener("click", function, true)






Example




document.getElementById("parent").addEventListener("click", function(){
console.log("Parent capturing");
}, true);






stopPropagation()



Stops the event from moving further.




document.getElementById("child").addEventListener("click", function(event){
event.stopPropagation();
console.log("Child only");
});






Output




Child only






Parent event will not run.



Example




document
↓
body
↓
parent
↓
child (clicked)
↑
parent
↑
body
↑
document







  • Capturing → top to bottom

  • Bubbling → bottom to top



6. Event Delegation



Instead of adding many event listeners, we can add one listener to the parent.



This technique is called event delegation.



It improves performance.



Example 1




<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>









document.getElementById("list").addEventListener("click", function(event){

if(event.target.tagName === "LI"){
console.log("You clicked:", event.target.innerText);
}

});






Output



Clicking any item shows:(The exact element that was clicked by the user)




You clicked: Item 2






Even if new <li> is added later, it still works.



7. Removing Event Listeners



We can remove an event listener using:



removeEventListener()



But the function must be named.



Example




function sayHello(){
console.log("Hello");
}

let btn = document.getElementById("btn");

btn.addEventListener("click", sayHello);

btn.removeEventListener("click", sayHello);






Anonymous functions cannot be removed easily.



Conclusion

JavaScript events are essential for creating interactive web applications. Understanding how events work helps developers handle user actions effectively and build dynamic user interfaces.

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - Understanding Events in JavaScript (Beginner Friendly Guide)
id: b9c29b00-dd6e-4a21-8726-343d93b1e782
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "Understanding Events in JavaSc" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Understanding Events in JavaScript Begin")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Understanding Events in JavaScript Begin*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Understanding Events in JavaScript Begin"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

CTI Threat Relationship Graph2 Knoten / 1 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Understanding Events in JavaScript (Begi.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Understanding Events in JavaScript (Beginner Friendly Guide)

Thematisch verwandte Begriffe: Understanding, Events, JavaScript, Beginner · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97735 | ITFlow before 26.08 allows SVG attachments in the ticket email parser (c…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag