{"id":126,"date":"2026-05-05T09:27:18","date_gmt":"2026-05-05T09:27:18","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=126"},"modified":"2026-05-05T09:27:19","modified_gmt":"2026-05-05T09:27:19","slug":"changing-content-and-styles","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles","title":{"rendered":"Changing Content and Styles"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduction<br>Changing content and styles is one of the most important features of JavaScript. It allows developers to update text, images, and design of a web page dynamically without reloading the page. This makes websites interactive and user friendly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Understanding Content Manipulation<br>JavaScript can access and modify HTML elements using the Document Object Model commonly known as the DOM. Developers can change text, images, links, and other elements based on user actions or conditions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Selecting Elements<br>To change content, you first need to select an HTML element. This can be done using methods like getElementById, querySelector, or getElementsByClassName.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let heading = document.getElementById(\"title\");<br>heading.textContent = \"Welcome to JavaScript\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Changing Text Content<br>JavaScript allows you to update the text inside an element easily. The textContent property is commonly used for this purpose.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>document.getElementById(\"para\").textContent = \"Content updated successfully\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Changing HTML Content<br>You can also change the inner HTML of an element using innerHTML. This allows adding tags along with text.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>document.getElementById(\"box\").innerHTML = \"&lt;b&gt;Bold Text Added&lt;\/b&gt;\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Changing Styles<br>JavaScript can modify CSS styles directly. This helps in changing colors, sizes, layouts, and visibility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>document.getElementById(\"box\").style.color = \"blue\";<br>document.getElementById(\"box\").style.backgroundColor = \"lightgray\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Adding and Removing Classes<br>Instead of directly changing styles, you can use classList to add or remove CSS classes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let element = document.getElementById(\"box\");<br>element.classList.add(\"active\");<br>element.classList.remove(\"hidden\");<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Changing Attributes<br>JavaScript can also change attributes like image source or links.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>document.getElementById(\"image\").src = \"newimage.jpg\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Practical Use Cases<br>Updating content after a button click<br>Changing theme or dark mode<br>Displaying dynamic data from users<br>Creating animations and effects<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion<br>Changing content and styles with JavaScript makes websites dynamic and interactive. It improves user experience by updating the page instantly without reload. Learning these techniques is essential for modern web development.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Intermediate JavaScript > DOM Manipulation > Changing Content and Styles<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777908335807\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777908335358\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-126","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Changing Content and Styles - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn how to change website content and styles using JavaScript DOM manipulation to create dynamic and interactive web pages easily\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Changing Content and Styles - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn how to change website content and styles using JavaScript DOM manipulation to create dynamic and interactive web pages easily\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-05T09:27:19+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=changing-content-and-styles\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=changing-content-and-styles\",\"name\":\"Changing Content and Styles - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-05T09:27:18+00:00\",\"dateModified\":\"2026-05-05T09:27:19+00:00\",\"description\":\"Learn how to change website content and styles using JavaScript DOM manipulation to create dynamic and interactive web pages easily\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=changing-content-and-styles#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=changing-content-and-styles\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=changing-content-and-styles#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate JavaScript > DOM Manipulation > Changing Content and Styles\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Changing Content and Styles - Learn JavaScript with GIGZ.PK","description":"Learn how to change website content and styles using JavaScript DOM manipulation to create dynamic and interactive web pages easily","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:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles","og_locale":"en_US","og_type":"article","og_title":"Changing Content and Styles - Learn JavaScript with GIGZ.PK","og_description":"Learn how to change website content and styles using JavaScript DOM manipulation to create dynamic and interactive web pages easily","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-05T09:27:19+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles","url":"https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles","name":"Changing Content and Styles - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-05T09:27:18+00:00","dateModified":"2026-05-05T09:27:19+00:00","description":"Learn how to change website content and styles using JavaScript DOM manipulation to create dynamic and interactive web pages easily","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=changing-content-and-styles#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Intermediate JavaScript > DOM Manipulation > Changing Content and Styles"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}