dom-creation Flashcards

1
Q

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

A

No, it doesn’t. It only creates an 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

parentElement.appendChild(childElement)

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 and value

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
  1. You create the new element
  2. element.appendChild(), call the appendChild method on the parent element already being displayed on the page. or on a parent element that will be appended on an element already being displayed on the page.
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

To set visible text of an element to be displayed on the screen.

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

elements.className = ‘new-class’ or element.classList.add(‘new-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

Reusability and effectiveness of code.

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