JAVASCRIPT EXAMPLE · BROWSER

DOM Text Update

DOM element select karke uska visible text JavaScript se update karo.

Working code

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

heading.textContent = "Welcome to BrounStack";
Run Code ▶

Expected output

Page ke <h1> ka text "Welcome to BrounStack" ho jayega.

How it works

querySelector("h1") first heading element select karta hai.

textContent selected element ka text safely replace karta hai.

Try Yourself

const heading = document.querySelector("h1");
heading.textContent = "JavaScript is working!";

Learn this concept

Read related JavaScript Tutorial →