Site Development Associate (1D0-61B)
1 Introduction to Site Development
1-1 Overview of Site Development
1-2 Role of a Site Development Associate
1-3 Industry Standards and Best Practices
2 HTML5 Fundamentals
2-1 HTML Document Structure
2-2 HTML Elements and Attributes
2-3 HTML Forms and Input Types
2-4 HTML5 Semantic Elements
3 CSS3 Essentials
3-1 CSS Syntax and Selectors
3-2 CSS Box Model
3-3 CSS Layout Techniques
3-4 CSS3 Animations and Transitions
4 JavaScript Basics
4-1 JavaScript Syntax and Variables
4-2 JavaScript Functions and Objects
4-3 DOM Manipulation
4-4 Event Handling in JavaScript
5 Responsive Web Design
5-1 Introduction to Responsive Design
5-2 Media Queries
5-3 Flexible Grid Systems
5-4 Responsive Images and Media
6 Web Accessibility
6-1 Understanding Web Accessibility
6-2 Accessibility Standards (WCAG)
6-3 Accessible Forms and Navigation
6-4 Testing for Accessibility
7 Version Control with Git
7-1 Introduction to Version Control
7-2 Git Basics: Init, Clone, Commit
7-3 Branching and Merging
7-4 Collaborating with Remote Repositories
8 Web Performance Optimization
8-1 Importance of Web Performance
8-2 Optimizing Images and Media
8-3 Minification and Concatenation
8-4 Caching Strategies
9 Introduction to Web Hosting
9-1 Types of Web Hosting
9-2 Domain Name System (DNS)
9-3 Setting Up a Web Server
9-4 Deploying a Website
10 Security in Web Development
10-1 Common Web Security Threats
10-2 Secure Coding Practices
10-3 Authentication and Authorization
10-4 HTTPS and SSLTLS
11 Project Management Basics
11-1 Introduction to Project Management
11-2 Agile vs Waterfall Methodologies
11-3 Tools for Project Management
11-4 Collaboration and Communication
12 Final Project
12-1 Project Planning and Requirements
12-2 Development and Implementation
12-3 Testing and Debugging
12-4 Deployment and Review
Event Handling in JavaScript

Event Handling in JavaScript

Key Concepts

Event Listeners

Event Listeners are functions that wait for a specific event to occur on an element. They are attached to elements using the addEventListener method. For example, to listen for a click event on a button:

        <button id="myButton">Click Me</button>
        <script>
            document.getElementById("myButton").addEventListener("click", function() {
                alert("Button clicked!");
            });
        </script>
    

Event Handlers

Event Handlers are functions that are executed when an event occurs. They can be defined inline in HTML or in JavaScript. For example, using an inline event handler:

        <button onclick="alert('Button clicked!')">Click Me</button>
    

Or using a JavaScript event handler:

        <button id="myButton">Click Me</button>
        <script>
            document.getElementById("myButton").onclick = function() {
                alert("Button clicked!");
            };
        </script>
    

Event Object

The Event Object is automatically passed to the event handler function and contains information about the event. It includes properties like type (the type of event), target (the element that triggered the event), and methods like preventDefault() (to stop the default action of the event). For example:

        <form id="myForm">
            <input type="text" id="myInput">
            <button type="submit">Submit</button>
        </form>
        <script>
            document.getElementById("myForm").addEventListener("submit", function(event) {
                event.preventDefault();
                alert("Form submission prevented!");
            });
        </script>
    

Event Propagation

Event Propagation refers to the order in which event handlers are called when an event occurs in nested elements. There are two types: Event Bubbling (from the innermost element to the outermost) and Event Capturing (from the outermost element to the innermost). For example, using Event Bubbling:

        <div id="outer">
            <div id="inner">Click Me</div>
        </div>
        <script>
            document.getElementById("inner").addEventListener("click", function() {
                alert("Inner div clicked!");
            });
            document.getElementById("outer").addEventListener("click", function() {
                alert("Outer div clicked!");
            });
        </script>
    

Examples and Analogies

Event Listeners Example

Think of Event Listeners as security cameras in a store. They are always on, waiting for a specific event (like a customer entering) to trigger an action (like recording the event).

Event Handlers Example

Consider Event Handlers as the store's security personnel. When the camera detects an event, the personnel (handler) takes action, such as calling the police or checking the footage.

Event Object Example

The Event Object is like the security report generated after an incident. It contains all the details (properties) about what happened and provides tools (methods) to manage the situation.

Event Propagation Example

Event Propagation is like a chain reaction in a domino setup. When the first domino falls (innermost element), it triggers the next one (outer element), and so on, until the entire setup is affected.