Skip to content
techsnow

The DOM

Changing Content and Styles

const title = document.querySelector("h1");

title.textContent = "Welcome back!";       // change text
title.style.color = "teal";                // inline style
title.classList.add("highlight");          // add a class
title.classList.remove("hidden");
title.classList.toggle("dark");            // add or remove

const img = document.querySelector("img");
img.src = "new-photo.jpg";                 // change an attribute
img.setAttribute("alt", "New photo");