Jul 11, 2024
document.body.append and appendChildbody.append('Hello World'): Directly appends strings and multiple elements.body.appendChild(element): Appends only one DOM node at a time.append for its versatility.document.createElement('div') to create elements.append method to add to the DOM.innerText vs. textContentinnerText: Considers CSS visibility, rendering only visible text.textContent: Ignores CSS visibility, includes all text and spacing.innerHTML to insert HTML content within elements (e.g., <strong>Hello</strong>).document.createElement for user-provided content.element.remove(): Directly removes the element from the DOM.parentElement.removeChild(element): Removes the specified child from its parent node.remove() for simplicity.element.getAttribute('id') and element.id: Retrieves the attribute value.element.setAttribute('id', 'newId') and element.id = 'newId': Sets new attribute values..id, .title) when available.element.removeAttribute('title'): Removes specified attribute.data- prefix (e.g., data-test).element.dataset (e.g., element.dataset.test).element.classList to manipulate class attributes.add(className): Adds a class.remove(className): Removes a class.toggle(className): Adds/removes class based on its presence.toggle(className, boolean): Adds/removes class based on the boolean value.element.style.propertyName.backgroundColor for background-color).