DOM_and_JS_Events_Presentation_simpleandShort.pptx

shivaninegi0435 11 views 10 slides Jul 31, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

a presentation explaining the js dom and events.topics included event handling , event listeners


Slide Content

Introduction to DOM and JavaScript Events UNDERSTANDING THE DOCUMENT OBJECT MODEL AND HOW TO HANDLE EVENTS IN JAVASCRIPT

Introduction to the DOM The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects; that way, programming languages can interact with the page.

Structure of the DOM The DOM is a tree structure. Each element, attribute, and piece of text is represented as a node. Example of a simple DOM tree.

Accessing DOM Elements Methods to access elements: getElementById, getElementsByClassName, getElementsByTagName, querySelector, querySelectorAll. Example: document.getElementById('example').

Manipulating DOM Elements Changing content: innerHTML, textContent. Changing styles: style.property. Adding and removing elements: appendChild, removeChild, createElement.

JavaScript Events Events are actions that happen in the browser. Examples: clicking a button, loading a page, pressing a key. Event types: Mouse events, Keyboard events, Form events, Document/Window events.

Event Handling Adding event listeners: addEventListener. Inline event handlers: onclick, onchange, etc. Example: document.getElementById('button').addEventListener('click', function() { alert('Button clicked!'); });

Event Propagation Event bubbling: The event starts from the target element and bubbles up to the root. Event capturing: The event starts from the root and goes down to the target element. Stopping propagation: stopPropagation.

Practical Examples Click events: Changing the content of a paragraph when a button is clicked. Form events: Validating input when a form is submitted. Keyboard events: Detecting key presses.

Thank You