DOM Manipulation & Events in JavaScript

🚀 Continuing Web Development Journey – DOM Manipulation & Events in JavaScript After learning advanced JavaScript concepts, I explored DOM Manipulation and Events, which are essential for making web pages interactive and dynamic. 🔹 What is DOM (Document Object Model)? The DOM represents the HTML structure as a tree of objects. JavaScript can use the DOM to access, modify, and update web page elements. 🔹 Selecting Elements JavaScript allows selecting HTML elements using different methods. let heading = document.getElementById("title"); let items = document.getElementsByClassName("item"); let para = document.querySelector("p"); 🔹 Changing Content We can modify text or HTML content. document.getElementById("title").innerHTML = "Updated Text"; 🔹 Changing Styles JavaScript can dynamically change styles. document.getElementById("title").style.color = "blue"; 🔹 Creating & Adding Elements let newElement = document.createElement("p"); newElement.innerText = "New Paragraph"; document.body.appendChild(newElement); 🔹 Removing Elements let element = document.getElementById("title"); element.remove(); 🔹 Events in JavaScript Events allow JavaScript to respond to user actions. Common events: • click • mouseover • keypress • submit 🔹 Event Handling Example <button onclick="showMessage()">Click Me</button> <script> function showMessage() { alert("Button Clicked!"); } </script> 🔹 Using addEventListener (Best Practice) document.getElementById("btn") .addEventListener("click", function() { console.log("Button clicked"); }); 🔹 Why DOM & Events are Important • Make web pages interactive • Dynamically update content • Handle user input efficiently • Essential for modern web applications Learning DOM manipulation and events is helping me build interactive and user-friendly web applications. #JavaScript #DOM #WebDevelopment #FrontendDevelopment #DotNetDeveloper #LearningJourney

To view or add a comment, sign in

Explore content categories