Aug 10, 2024
Selecting Elements:
document.querySelector()
to select elements.document.querySelector('.box').innerHTML
retrieves HTML content of the first .box
element.Inner and Outer HTML:
Text Content:
textContent
to access only the text content of an element, excluding HTML tags.Node Name vs. Tag Name:
nodeName
: applicable for all node types (e.g., comment, text).tagName
: applicable only for element nodes.Managing Attributes:
element.hasAttribute()
: checks for the existence of an attribute.element.getAttribute()
: retrieves the value of an attribute.element.setAttribute()
: sets or updates an attribute.element.removeAttribute()
: removes an attribute.