dom-creation Flashcards

1
Q

Does the document.createElement() method insert a new element into the page?

A
No, This element node is stored
in a variable.
When the element node is
created, it is not yet part of the
DOM tree. It is not added to
the DOM tree until step 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you add an element as a child to another element?

A

appendChild()

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

What do you pass as the arguments to the element.setAttribute() method?

A

name
A DOMString specifying the name of the attribute whose value is to be set. The attribute name is automatically converted to all lower-case when setAttribute() is called on an HTML element in an HTML document.

value
A DOMString containing the value to assign to the attribute. Any non-string value specified is converted automatically into a string.

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

What steps do you need to take in order to insert a new element into the page?

A
CREATE THE ELEMENT
createEl ement ()
You start by creating a new
element node using the
createElement() method.
This element node is stored
in a variable.
When the element node is
created, it is not yet part of the
DOM tree. It is not added to
the DOM tree until step 3.

Create TextNode

appendChild

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

What is the textContent property of an element object for?

A

textContent gets the content of all elements. The textContent property of the Node interface represents the text content of the node and its descendants.

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

Name two ways to set the class attribute of a DOM element.

A

className, setAttribute

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

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

you can repeatedly call the function, simplifies code, encapsulate the functionaility for rendering the dom tree, can just change the function instead of the rest of the code

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