Accessing Elements in the DOM
getElementById(): Selects an element with a specific
getElementsByClassName(): Selects all elements with a specific
getElementsByTagName(): Selects all elements with a specific tag name, such as
querySelector(): Selects the first element that matches a CSS selector, such as
querySelectorAll(): Selects all elements that match a CSS selector.
Adding and Removing Elements
createElement(): Creates a new element with a specified tag name.
createTextNode(): Creates a new text node with a specified text content.
appendChild(): Adds a new child element to a parent element.
insertBefore(): Inserts a new child element before an existing child element.
removeChild(): Removes a child element from a parent element.
Handling Events and User Interactions
- Adding event listeners using the
addEventListener()method to listen for specific events, such as
- Removing event listeners using the
- Using event objects to access information about the event, such as the target element or the type of event.