dom-creation Flashcards
Does the document.createElement() method insert a new element into the page?
No, it doesn’t. It only creates an element.
How do you add an element as a child to another element?
parentElement.appendChild(childElement)
What do you pass as the arguments to the element.setAttribute() method?
name and value
What steps do you need to take in order to insert a new element into the page?
- You create the new element
- 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.
What is the textContent property of an element object for?
To set visible text of an element to be displayed on the screen.
Name two ways to set the class attribute of a DOM element.
elements.className = ‘new-class’ or element.classList.add(‘new-value’);
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
Reusability and effectiveness of code.