dom-creation Flashcards
Does the document.createElement() method insert a new element into the page?
No, it just creates it
How do you add an element as a child to another element?
element.appendChild()
What do you pass as the arguments to the element.setAttribute() method?
name of the attribute to be set, value to assign the attribute
What steps do you need to take in order to insert a new element into the page?
- create the element with createElement()
- Give it content (optional) with createTextNode()
- Add it to the DOM ( appendChild() )
What is the textContent property of an element object for?
it either returns the value of the text in the node or it assigns text to the node.
Name two ways to set the class attribute of a DOM element.
className and classList
What are two advantages of defining a function to create something (like the work of creating a DOM tree)?
Reusability, Separation of concerns, improved testability