{"id":560,"date":"2025-05-19T10:52:05","date_gmt":"2025-05-19T10:52:05","guid":{"rendered":"https:\/\/buhave.com\/courses\/?p=560"},"modified":"2026-06-06T13:51:19","modified_gmt":"2026-06-06T13:51:19","slug":"dom-manipulation","status":"publish","type":"post","link":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/","title":{"rendered":"DOM Manipulation"},"content":{"rendered":"<h2>What is the DOM?<\/h2>\n<h3>DOM Meaning<\/h3>\n<p>The DOM connects web pages to programming languages like <a href=\"https:\/\/buhave.com\/courses\/java-script\/introduction-to-javascript\/\">JavaScript<\/a>, allowing you to change the page dynamically. This model also serves as a bridge between the document and scripting, enabling interactive updates without reloads.<\/p>\n<p><strong>In simple words:<\/strong><\/p>\n<p>The DOM helps link web pages to programming languages like JavaScript, allowing dynamic changes to the page.<\/p>\n<p><strong>Structure of the DOM<\/strong><\/p>\n<ul>\n<li>The whole web page becomes a tree of nodes.<\/li>\n<li>Each HTML element (like &lt;h1&gt;, &lt;p&gt;, &lt;div&gt;) is a node in the tree.<\/li>\n<li>There are different types of nodes:<\/li>\n<li>Document node (the root, entire page)<\/li>\n<li>Element nodes (tags like &lt;p&gt;, &lt;img&gt;)<\/li>\n<li>Text nodes (text inside elements)<\/li>\n<li>Attribute nodes (like class=&#8221;title&#8221;)<\/li>\n<\/ul>\n<p><strong>Example:<\/strong> Simple HTML Page and DOM<\/p>\n<p><strong>HTML:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;!DOCTYPE html&gt;<\/em><br \/>\n<em>&lt;html&gt;<\/em><br \/>\n<em>&lt;body&gt;<\/em><br \/>\n<em>&lt;h1&gt;Hello World&lt;\/h1&gt;<\/em><br \/>\n<em>&lt;p&gt;Welcome to the DOM.&lt;\/p&gt;<\/em><br \/>\n<em>&lt;\/body&gt;<\/em><br \/>\n<em>&lt;\/html&gt;<\/em><\/p>\n<p><strong>DOM Tree:<\/strong><\/p>\n<p style=\"text-align: center\"><em>Document<\/em><br \/>\n<em>\u2514\u2500\u2500 html<\/em><br \/>\n<em>\u2514\u2500\u2500 body<\/em><br \/>\n<em>\u251c\u2500\u2500 h1<\/em><br \/>\n<em>\u2502 \u2514\u2500\u2500 &#8220;Hello World&#8221;<\/em><br \/>\n<em>\u2514\u2500\u2500 p<\/em><br \/>\n<em>\u2514\u2500\u2500 &#8220;Welcome to the DOM.&#8221;<\/em><\/p>\n<p>The DOM turns HTML into a structure that <a href=\"https:\/\/buhave.com\/courses\/java-script\/introduction-to-javascript\/\">JavaScript<\/a> can read and manipulate.<\/p>\n<h3>How JavaScript Interacts with the DOM<\/h3>\n<p><strong>You can use JavaScript to:<\/strong><\/p>\n<ul>\n<li>Select elements (getElementById, querySelector, etc.)<\/li>\n<li>Change content (element.textContent, element.innerHTML)<\/li>\n<li>Change styles (element.style.color = &#8220;red&#8221;)<\/li>\n<li>Add or remove elements (appendChild, removeChild)<\/li>\n<li>Handle events (clicks, typing, scrolling)<\/li>\n<\/ul>\n<p>For a quick refresher on how JavaScript works with the DOM, see our <a href=\"https:\/\/buhave.com\/courses\/java-script\/introduction-to-javascript\/\">Introduction to JavaScript<\/a> course.<\/p>\n<p><strong>Example:<\/strong> Changing Text Using the DOM<\/p>\n<p style=\"text-align: center\"><em>&lt;h1 id=&#8221;title&#8221;&gt;Hello&lt;\/h1&gt;<\/em><\/p>\n<p style=\"text-align: center\"><em>&lt;script&gt;<\/em><br \/>\n<em>const heading = document.getElementById(&#8220;title&#8221;);<\/em><br \/>\n<em>heading.textContent = &#8220;Hello, DOM World!&#8221;;<\/em><br \/>\n<em>&lt;\/script&gt;<\/em><\/p>\n<p>The &lt;h1&gt; content changes when the script runs.<\/p>\n<p><strong>Why the DOM is Important<\/strong><\/p>\n<ul>\n<li>Dynamic updates without reloading the page.<\/li>\n<li>Interactive websites (like buttons, forms, pop-ups).<\/li>\n<li>Control over structure, style, and content of a webpage.<\/li>\n<\/ul>\n<p>Without the DOM, JavaScript could not manipulate HTML and webpages would be static.<\/p>\n<p><strong>Quick Summary:<\/strong><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<thead>\n<tr>\n<th>Topic<\/th>\n<th>Explanation<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>DOM Definition<\/td>\n<td>Interface that represents HTML\/XML pages as trees<\/td>\n<\/tr>\n<tr>\n<td>DOM Purpose<\/td>\n<td>Connects web pages with programming languages<\/td>\n<\/tr>\n<tr>\n<td>DOM Structure<\/td>\n<td>Tree with nodes (Document, Element, Text, Attribute)<\/td>\n<\/tr>\n<tr>\n<td>JavaScript Role<\/td>\n<td>Access and change elements dynamically<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Selecting elements (getElementById, querySelector, etc.)<\/h2>\n<p><strong>Why Select Elements?<\/strong><\/p>\n<p>Selecting elements means grabbing HTML elements using JavaScript so you can read, change, or manipulate them.<br \/>\nYou can modify text, style, attributes, or even react to user actions like clicks.<\/p>\n<h3>Common Methods to Select Elements<\/h3>\n<p><strong>1. GetElementById()<\/strong><\/p>\n<ul>\n<li>Purpose: Selects one element with a specific id.<\/li>\n<li>Returns: A single element (or null if not found).<\/li>\n<li>Fastest method for selecting.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>const element = document.getElementById(&#8220;elementId&#8221;);<\/em><\/p>\n<p><strong>Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;h1 id=&#8221;main-title&#8221;&gt;Welcome!&lt;\/h1&gt;<\/em><\/p>\n<p style=\"text-align: center\"><em>const title = document.getElementById(&#8220;main-title&#8221;);<\/em><br \/>\n<em>console.log(title.textContent); \/\/ &#8220;Welcome!&#8221;<\/em><\/p>\n<p><strong data-start=\"931\" data-end=\"939\">Tip:<\/strong> IDs must be unique on a page.<\/p>\n<p><strong>2. getElementsByClassName()<\/strong><\/p>\n<ul>\n<li>Purpose: Selects all elements with a specific class name.<\/li>\n<li>Returns: An HTMLCollection (looks like an array but not exactly).<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>const elements = document.getElementsByClassName(&#8220;className&#8221;);<\/em><\/p>\n<p><strong>Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;p class=&#8221;info&#8221;&gt;Info 1&lt;\/p&gt;<\/em><br \/>\n<em>&lt;p class=&#8221;info&#8221;&gt;Info 2&lt;\/p&gt;<\/em><\/p>\n<p style=\"text-align: center\"><em>const infoItems = document.getElementsByClassName(&#8220;info&#8221;);<\/em><br \/>\n<em>console.log(infoItems.length); \/\/ 2<\/em><\/p>\n<p>Access with index infoItems[0], infoItems[1].<\/p>\n<p><strong>3. getElementsByTagName()<\/strong><\/p>\n<ul>\n<li>Purpose: Selects all elements of a specific tag (like p, div, h1).<\/li>\n<li>Returns: An HTMLCollection.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>const paragraphs = document.getElementsByTagName(&#8220;p&#8221;);<\/em><\/p>\n<p><strong>Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;p&gt;Paragraph 1&lt;\/p&gt;<\/em><br \/>\n<em>&lt;p&gt;Paragraph 2&lt;\/p&gt;<\/em><\/p>\n<p style=\"text-align: center\"><em>const allParagraphs = document.getElementsByTagName(&#8220;p&#8221;);<\/em><br \/>\n<em>console.log(allParagraphs.length); \/\/ 2<\/em><\/p>\n<p><strong>4. querySelector()<\/strong><\/p>\n<ul>\n<li>Purpose: Selects the first element that matches a CSS selector.<\/li>\n<li>Returns: A single element (or null if none found).<\/li>\n<li>Very powerful and flexible.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>const element = document.querySelector(&#8220;selector&#8221;);<\/em><\/p>\n<p><strong>Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;div class=&#8221;box&#8221;&gt;Box 1&lt;\/div&gt;<\/em><br \/>\n<em>&lt;div class=&#8221;box&#8221;&gt;Box 2&lt;\/div&gt;<\/em><\/p>\n<p style=\"text-align: center\"><em>const firstBox = document.querySelector(&#8220;.box&#8221;);<\/em><br \/>\n<em>console.log(firstBox.textContent); \/\/ &#8220;Box 1&#8221;<\/em><\/p>\n<p><strong>CSS Selectors:<\/strong> IDs (#id), classes (.class), tags (div), attributes ([type=&#8221;text&#8221;]).<\/p>\n<p><strong>5. querySelectorAll()<\/strong><\/p>\n<ul>\n<li>Purpose: Selects all elements that match a CSS selector.<\/li>\n<li>Returns: A NodeList (can use forEach).<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\">c<em>onst elements = document.querySelectorAll(&#8220;selector&#8221;);<\/em><\/p>\n<p><strong>Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;p class=&#8221;highlight&#8221;&gt;First&lt;\/p&gt;<\/em><br \/>\n<em>&lt;p class=&#8221;highlight&#8221;&gt;Second&lt;\/p&gt;<\/em><\/p>\n<p style=\"text-align: center\"><em>const highlights = document.querySelectorAll(&#8220;.highlight&#8221;);<\/em><br \/>\n<em>highlights.forEach(item =&gt; console.log(item.textContent));<\/em><\/p>\n<p><strong>HTMLCollection vs. NodeList<\/strong><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<thead>\n<tr>\n<th>Feature<\/th>\n<th>HTMLCollection<\/th>\n<th>NodeList<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Returned by<\/td>\n<td>getElementsByClassName, getElementsByTagName<\/td>\n<td>querySelectorAll<\/td>\n<\/tr>\n<tr>\n<td>Live Update<\/td>\n<td>Yes (updates if DOM changes)<\/td>\n<td>No (static snapshot)<\/td>\n<\/tr>\n<tr>\n<td>forEach() Method<\/td>\n<td>(needs conversion)<\/td>\n<td>(direct use)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Choosing the Right Method<\/strong><\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif\" border=\"1\" cellspacing=\"0\" cellpadding=\"8\">\n<thead style=\"background-color: #f2f2f2\">\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #ddd\">Situation<\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #ddd\">Best Method<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Need single element by ID<\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\"><code>getElementById()<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Need elements by class name or tag<\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\"><code>getElementsByClassName()<\/code>,<br \/>\n<code>getElementsByTagName()<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Need first match by CSS selector<\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\"><code>querySelector()<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px\">Need all matches by CSS selector<\/td>\n<td style=\"padding: 12px\"><code>querySelectorAll()<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Real Example &#8211; Full Flow<\/strong><\/p>\n<p><strong>HTML:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;h1 id=&#8221;site-title&#8221;&gt;Hello&lt;\/h1&gt;<\/em><br \/>\n<em>&lt;p class=&#8221;description&#8221;&gt;First paragraph.&lt;\/p&gt;<\/em><br \/>\n<em>&lt;p class=&#8221;description&#8221;&gt;Second paragraph.&lt;\/p&gt;<\/em><\/p>\n<p>New to HTML? See our <a href=\"https:\/\/buhave.com\/courses\/html\/introduction-to-html\/\">Introduction to HTML<\/a> course for fundamentals.<\/p>\n<p><strong>JavaScript:<\/strong><\/p>\n<p style=\"text-align: center\"><em>const title = document.getElementById(&#8220;site-title&#8221;);<\/em><br \/>\n<em>const descriptions = document.getElementsByClassName(&#8220;description&#8221;);<\/em><br \/>\n<em>const firstParagraph = document.querySelector(&#8220;.description&#8221;);<\/em><br \/>\n<em>const allParagraphs = document.querySelectorAll(&#8220;.description&#8221;);<\/em><\/p>\n<p style=\"text-align: center\"><em>console.log(title.textContent); \/\/ Hello<\/em><br \/>\n<em>console.log(descriptions.length); \/\/ 2<\/em><br \/>\n<em>console.log(firstParagraph.textContent); \/\/ First paragraph.<\/em><br \/>\n<em>allParagraphs.forEach(p =&gt; console.log(p.textContent));<\/em><\/p>\n<p><strong>Quick Summary:<\/strong><\/p>\n<p>In JavaScript, you can select elements using methods like getElementById, querySelector, getElementsByClassName, and querySelectorAll to manipulate or interact with the page easily.<\/p>\n<h2>Changing content and styles<\/h2>\n<p><strong>Why Change Content and Styles?<\/strong><\/p>\n<p>Using JavaScript, you can dynamically update:<\/p>\n<ul>\n<li>Text<\/li>\n<li>HTML structure<\/li>\n<li>CSS styles<\/li>\n<\/ul>\n<p>This makes websites interactive, dynamic, and user-friendly \u2014 no page reload needed!<\/p>\n<h3>Changing Content<\/h3>\n<p><strong>There are several ways to change the content of HTML elements:<\/strong><\/p>\n<p><strong>1. Text Content<\/strong><\/p>\n<ul>\n<li>Sets or gets the text inside an element.<\/li>\n<li>Ignores HTML tags, treats everything as plain text.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>element.textContent = &#8220;New Text Here&#8221;;<\/em><\/p>\n<p><strong>HTML:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;p id=&#8221;greet&#8221;&gt;Hello!&lt;\/p&gt;<\/em><\/p>\n<p><strong>JavaScript:<\/strong><\/p>\n<p style=\"text-align: center\"><em>const greet = document.getElementById(&#8220;greet&#8221;);<\/em><br \/>\n<em>greet.textContent = &#8220;Welcome to the site!&#8221;;<\/em><\/p>\n<p><strong>Result:<\/strong> Only text is inserted.<\/p>\n<p><strong>2. Inner HTML<\/strong><\/p>\n<ul>\n<li>Sets or gets the HTML content inside an element.<\/li>\n<li>Allows HTML tags inside.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>element.innerHTML = &#8220;&lt;strong&gt;Bold Text&lt;\/strong&gt;&#8221;;<\/em><\/p>\n<p><strong>Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;div id=&#8221;content&#8221;&gt;&lt;\/div&gt;<\/em><\/p>\n<p><strong>JavaScript:<\/strong><\/p>\n<p style=\"text-align: center\"><em>const content = document.getElementById(&#8220;content&#8221;);<\/em><br \/>\n<em>content.innerHTML = &#8220;&lt;h2&gt;New Heading&lt;\/h2&gt;&lt;p&gt;New paragraph!&lt;\/p&gt;&#8221;;<\/em><\/p>\n<ul>\n<li><strong>Result:<\/strong> HTML structure is rendered inside the div.<\/li>\n<li><strong>Warning:<\/strong> Using innerHTML can open security risks (like XSS attacks) if you insert untrusted content.<\/li>\n<\/ul>\n<h2>Handling events (click, input, submit)<\/h2>\n<p><strong>Handling Events in JavaScript<\/strong><\/p>\n<p>JavaScript allows you to handle user interactions (events) like clicks, inputs, and form submissions to make web pages dynamic. Events are triggered by user actions, such as clicking a button or typing in a text box, and JavaScript listens for these events to execute a function.<\/p>\n<p>For a deeper dive into event handling patterns, see our <a href=\"https:\/\/buhave.com\/courses\/java-script\/advanced-javascript-concepts\/\">Advanced JavaScript Concepts<\/a> course.<\/p>\n<h3>There are many types of Handling Events in JavaScript.<\/h3>\n<p><strong>1. Event Types<\/strong><\/p>\n<ul>\n<li>Click: Triggered when a user clicks an element (e.g., button, link).<\/li>\n<li>Input: Triggered when a user types into a text field or textarea.<\/li>\n<li>Submit: Triggered when a user submits a form.<\/li>\n<\/ul>\n<p><strong>2. Attaching Event Listeners<\/strong><\/p>\n<p><strong>Method 1:<\/strong> Using addEventListener()<\/p>\n<p>The addEventListener() method attaches an event handler to an element. It\u2019s flexible and allows multiple event listeners for the same event.<\/p>\n<p><strong>Example &#8211; Handling a Click Event:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;button id=&#8221;myButton&#8221;&gt;Click Me&lt;\/button&gt;<\/em><\/p>\n<p style=\"text-align: center\"><em>&lt;script&gt;<\/em><br \/>\n<em>const button = document.getElementById(&#8216;myButton&#8217;);<\/em><br \/>\n<em>button.addEventListener(&#8216;click&#8217;, function() {<\/em><br \/>\n<em>alert(&#8216;Button clicked!&#8217;);<\/em><br \/>\n<em>});<\/em><br \/>\n<em>&lt;\/script&gt;<\/em><\/p>\n<p><strong>Example &#8211; Handling Input Event:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&lt;input type=&#8221;text&#8221; id=&#8221;myInput&#8221; placeholder=&#8221;Ty<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is the DOM? DOM Meaning The DOM connects web pages to programming languages like JavaScript, allowing you to change [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":562,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[13],"tags":[],"class_list":["post-560","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-script"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DOM Manipulation - Java Script Course<\/title>\n<meta name=\"description\" content=\"DOM Manipulation means dynamically creating, editing, and removing HTML elements to update a web page instantly.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DOM Manipulation - Java Script Course\" \/>\n<meta property=\"og:description\" content=\"DOM Manipulation means dynamically creating, editing, and removing HTML elements to update a web page instantly.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/\" \/>\n<meta property=\"og:site_name\" content=\"BUHAVE\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BeYouHave\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/naveedsafdarawan\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-19T10:52:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-06T13:51:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/DOM-Manipulation.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Naveed Safdar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Naveed Safdar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/\"},\"author\":{\"name\":\"Naveed Safdar\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\"},\"headline\":\"DOM Manipulation\",\"datePublished\":\"2025-05-19T10:52:05+00:00\",\"dateModified\":\"2026-06-06T13:51:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/\"},\"wordCount\":1228,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/DOM-Manipulation.webp\",\"articleSection\":[\"Java Script Course\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/\",\"name\":\"DOM Manipulation - Java Script Course\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/DOM-Manipulation.webp\",\"datePublished\":\"2025-05-19T10:52:05+00:00\",\"dateModified\":\"2026-06-06T13:51:19+00:00\",\"description\":\"DOM Manipulation means dynamically creating, editing, and removing HTML elements to update a web page instantly.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/DOM-Manipulation.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/DOM-Manipulation.webp\",\"width\":1200,\"height\":628,\"caption\":\"DOM Manipulation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/java-script\\\/dom-manipulation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Script Course\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/learn\\\/java-script\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"DOM Manipulation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"name\":\"BUHAVE\",\"description\":\"Courses - Learn Online for Free\",\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/buhave.com\\\/courses\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\",\"name\":\"BUHAVE\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"width\":375,\"height\":75,\"caption\":\"BUHAVE\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/BeYouHave\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/buhave\",\"https:\\\/\\\/www.youtube.com\\\/@buhave\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\",\"name\":\"Naveed Safdar\",\"description\":\"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/naveedsafdar\\\/\",\"https:\\\/\\\/www.facebook.com\\\/naveedsafdarawan\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@naveedsafdar\"],\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/author\\\/naveed-safdar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DOM Manipulation - Java Script Course","description":"DOM Manipulation means dynamically creating, editing, and removing HTML elements to update a web page instantly.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/","og_locale":"en_US","og_type":"article","og_title":"DOM Manipulation - Java Script Course","og_description":"DOM Manipulation means dynamically creating, editing, and removing HTML elements to update a web page instantly.","og_url":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/","og_site_name":"BUHAVE","article_publisher":"https:\/\/www.facebook.com\/BeYouHave\/","article_author":"https:\/\/www.facebook.com\/naveedsafdarawan\/","article_published_time":"2025-05-19T10:52:05+00:00","article_modified_time":"2026-06-06T13:51:19+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/DOM-Manipulation.webp","type":"image\/webp"}],"author":"Naveed Safdar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Naveed Safdar","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/#article","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/"},"author":{"name":"Naveed Safdar","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca"},"headline":"DOM Manipulation","datePublished":"2025-05-19T10:52:05+00:00","dateModified":"2026-06-06T13:51:19+00:00","mainEntityOfPage":{"@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/"},"wordCount":1228,"commentCount":0,"publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"image":{"@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/DOM-Manipulation.webp","articleSection":["Java Script Course"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/","url":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/","name":"DOM Manipulation - Java Script Course","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/#website"},"primaryImageOfPage":{"@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/#primaryimage"},"image":{"@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/DOM-Manipulation.webp","datePublished":"2025-05-19T10:52:05+00:00","dateModified":"2026-06-06T13:51:19+00:00","description":"DOM Manipulation means dynamically creating, editing, and removing HTML elements to update a web page instantly.","breadcrumb":{"@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/#primaryimage","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/DOM-Manipulation.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/DOM-Manipulation.webp","width":1200,"height":628,"caption":"DOM Manipulation"},{"@type":"BreadcrumbList","@id":"https:\/\/buhave.com\/courses\/java-script\/dom-manipulation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Courses","item":"https:\/\/buhave.com\/courses\/"},{"@type":"ListItem","position":2,"name":"Java Script Course","item":"https:\/\/buhave.com\/courses\/learn\/java-script\/"},{"@type":"ListItem","position":3,"name":"DOM Manipulation"}]},{"@type":"WebSite","@id":"https:\/\/buhave.com\/courses\/#website","url":"https:\/\/buhave.com\/courses\/","name":"BUHAVE","description":"Courses - Learn Online for Free","publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/buhave.com\/courses\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/buhave.com\/courses\/#organization","name":"BUHAVE","url":"https:\/\/buhave.com\/courses\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","width":375,"height":75,"caption":"BUHAVE"},"image":{"@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/BeYouHave\/","https:\/\/www.linkedin.com\/company\/buhave","https:\/\/www.youtube.com\/@buhave"]},{"@type":"Person","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca","name":"Naveed Safdar","description":"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.","sameAs":["https:\/\/www.linkedin.com\/in\/naveedsafdar\/","https:\/\/www.facebook.com\/naveedsafdarawan\/","https:\/\/www.youtube.com\/@naveedsafdar"],"url":"https:\/\/buhave.com\/courses\/author\/naveed-safdar\/"}]}},"_links":{"self":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/comments?post=560"}],"version-history":[{"count":2,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/560\/revisions"}],"predecessor-version":[{"id":1161,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/560\/revisions\/1161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media\/562"}],"wp:attachment":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media?parent=560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/categories?post=560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/tags?post=560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}