dom Flashcards
(6 cards)
DOM definition
tree like representation of a HTML document
allows programs that are organized to access and modify content, structure and styles
How is the DOM structured?
The document is the root node.
Elements (e.g., <html>, <div>) are child nodes.
Attributes (e.g., class, id) and text content are nodes within elements.
Name 2 DOM objects and their purposes.
getElementById(id): Selects an element by its id attribute.
querySelector(cssSelector): Selects the first element matching a CSS selector.
What are innerHTML and textContent?
innerHTML: Gets/sets the HTML content inside an element (including tags).
textContent: Gets/sets only the text content (ignores HTML tags).
Name 3 DOM traversal properties.
parentNode: Selects the parent of a node.
childNodes: Returns a list of child nodes.
nextSibling/previousSibling: Navigates between sibling nodes.
What’s the difference between HTML and the DOM?
HTML: Static source code of the webpage.
DOM: Dynamic, in-memory representation of the HTML that can be modified by JavaScript.