dom Flashcards

(6 cards)

1
Q

DOM definition

A

tree like representation of a HTML document

allows programs that are organized to access and modify content, structure and styles

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is the DOM structured?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name 2 DOM objects and their purposes.

A

getElementById(id): Selects an element by its id attribute.

querySelector(cssSelector): Selects the first element matching a CSS selector.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are innerHTML and textContent?

A

innerHTML: Gets/sets the HTML content inside an element (including tags).

textContent: Gets/sets only the text content (ignores HTML tags).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name 3 DOM traversal properties.

A

parentNode: Selects the parent of a node.

childNodes: Returns a list of child nodes.

nextSibling/previousSibling: Navigates between sibling nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s the difference between HTML and the DOM?

A

HTML: Static source code of the webpage.

DOM: Dynamic, in-memory representation of the HTML that can be modified by JavaScript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly