JavaScript (ECMAScript) is the foundational high-level, interpreted programming language of the modern World Wide Web. While HTML defines the static semantic structure and CSS handles visual styling, JavaScript injects dynamic behavior, reactivity, state manipulation, and interactive application logic into the browser.
When a browser loads a web page:
document and window objects.innerHTMLThe DOM represents an HTML document as a structured hierarchy of JavaScript objects. Each HTML element on your page (such as <div>, <h1>, <button>) is an instance of the HTMLElement interface.
document.getElementById(id): Searches the active document for an element whose unique id attribute matches the provided string. Returns the element object if found, or null if no matching element exists.element.innerHTML: A read/write property that gets or sets the HTML or XML markup contained within the element. Setting innerHTML wipes any existing children and forces the browser to parse the new string and reconstruct DOM subnodes immediately.// Selecting an element by its ID and updating its contents
const header = document.getElementById("welcome-banner");
header.innerHTML = "Welcome to Tentier Network!";// Example A: Updating a Web3 user dashboard balance
const balanceDisplay = document.getElementById("user-balance");
const currentUsdt = 350.75;
balanceDisplay.innerHTML = "<strong>" + currentUsdt + " USDT</strong>";
// Example B: Rendering dynamic status badge
const badge = document.getElementById("node-status");
badge.innerHTML = '<span class="badge-active">Online ยท 99.9% Uptime</span>';id must be completely unique within an HTML document. Having multiple elements with the same id violates HTML standards and causes document.getElementById() to only select the first matching node.innerHTML. Prefer element.textContent or sanitize with DOMPurify to prevent malicious script injection.innerHTML inside tight loops forces continuous browser layout recalculations (reflows). Batch your updates or modify elements in memory before mounting them.---
<h1> tag with id="greeting" that currently displays "Old Text".document.getElementById("greeting").innerHTML property to "Welcome to JavaScript on Ten Tier!".---
Browser Preview:
Welcome to JavaScript on Ten Tier!(The heading text immediately updates from "Old Text" to "Welcome to JavaScript on Ten Tier!")