dom creation Flashcards

1
Q

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

A

no, it only creates it

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

parent.appendChild(child)

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

attribute name, attribute value (strings)

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, document.createElement(‘type’)

give it content, document.createTextNode(‘text’)

add the text node to the element node, element.appendChild(textNode)

add it to the dom, parent.appendChild(child)

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

retrieving and setting the text of an html 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
  1. element.className

2. element.setAttribute(‘class’, ‘className’)

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
  1. reusability

2. versatility, can pass different arguments as needed

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