SyntaxStudy
Sign Up
JavaScript Beginner 1 min read

Changing HTML & CSS

Changing HTML & CSS

Content

  • innerHTML — HTML markup
  • textContent — plain text (safer)

CSS

  • element.style.color — inline style
  • classList.add/remove/toggle — preferred
Example
const box=document.querySelector('.box');
box.textContent='New text';
box.style.backgroundColor='#6366f1';
box.classList.add('active');
box.classList.toggle('dark');