dom-creation Flashcards

1
Q

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

A

The document.createElement() method does not insert a new element into the page. It makes a new element.

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

To add an element as a child to another element use the .appendChild() method -> parent element.appendChild(child element)

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

The arguments are passed to element.setAttribute() with the two arguments being name and value. That element will now have an attribute of name and assign the value to it.

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

The steps needed to insert a new element into the page is the creation of an element. Query the DOM for a parent to appendChild() on. Then run parent element.appendChild(child element) with the child element being created in JavaScript.

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

The textContent property of an element object is to get or set the text content of that element.

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

Two ways to set the class attribute of a DOM element are: element.className = “” and element.setAttribute(‘class’, value);

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

Two advantages of defining a function to create something are: that thing can be created for many alternative versions (pokemon cards) and to separate out the action of creating elements versus adding the elements to the DOM to change the appearance of the webpage.

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