Change text, classes and attributes

textContent is safe for text. classList adds, removes and toggles classes.

JavaScript · Change text, classes and attributesBeginner
const box = document.querySelector('.box');

box.textContent = 'Hello';                 // plain text (safe)
box.classList.add('active');
box.classList.remove('hidden');
box.classList.toggle('open');              // add if missing, remove if present
const isOpen = box.classList.contains('open');

box.setAttribute('data-id', '42');
box.style.color = 'green';
box.hidden = false;
textContentclassListsetAttributedom