dom creation Flashcards
Does the document.createElement() method insert a new element into the page?
no, it only creates it
How do you add an element as a child to another element?
parent.appendChild(child)
What do you pass as the arguments to the element.setAttribute() method?
attribute name, attribute value (strings)
What steps do you need to take in order to insert a new element into the page?
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)
What is the textContent property of an element object for?
retrieving and setting the text of an html element
Name two ways to set the class attribute of a DOM element.
- element.className
2. element.setAttribute(‘class’, ‘className’)
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
- reusability
2. versatility, can pass different arguments as needed