JAVASCRIPT Tutorial
document.querySelector()
or document.querySelectorAll()
to select the element you want to modify.innerHTML
, textContent
, innerText
) to set or retrieve the element's content.createElement()
to create new HTML elements and customize their attributes and content.appendChild()
, removeChild()
, or insertBefore()
to manipulate the element's child list.// Change the text content of a heading
const heading = document.querySelector('h1');
heading.textContent = 'New Heading Text';
// Add a new paragraph element
const newParagraph = document.createElement('p');
newParagraph.textContent = 'This is a new paragraph.';
document.body.appendChild(newParagraph);
// Remove an existing element
const oldElement = document.querySelector('#oldElement');
document.body.removeChild(oldElement);