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