Category: javascript
DOM manipulation
Published on 16 Jul 2026
Explanation
DOM manipulation changes HTML content dynamically.
Code:
document.getElementById('msg').textContent = 'Hello';
Explanation
HTML content can be updated using innerHTML.
Code:
document.getElementById('box').innerHTML = '<b>Hi</b>';
Explanation
CSS styles can be changed using JavaScript.
Code:
document.getElementById('box').style.color = 'red';
Explanation
New elements can be created and added to the page.
Code:
const p = document.createElement('p');
p.textContent = 'New Paragraph';
Explanation
Elements can also be removed from the DOM.
Code:
document.getElementById('box').remove();