Hackforge Academy

Category: javascript

dom changing content innerhtml textcontent value

Published on 30 Sep 2026

Explanation

innerHTML gets or replaces the HTML content inside an element.

Code:

document.getElementById('box').innerHTML =
  '<strong>Hello</strong>';

Explanation

textContent gets or replaces plain text content without interpreting the value as HTML.

Code:

document.getElementById('message').textContent =
  'Welcome to JavaScript';

Explanation

The value property is used to read or change the current value of form controls such as input elements.

Code:

const name = document.getElementById('name').value;

console.log(name);

Explanation

Assign a value to an input field using its value property.

Code:

document.getElementById('name').value = 'Praveen';

Explanation

Use textContent when inserting plain user-provided text to avoid interpreting it as HTML.

Code:

const message = '<b>Hello</b>';

document.getElementById('output').textContent = message;

// Displays the text literally

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community