DOM Creation Flashcards
Does thedocument.createElement( )method insert a new element into the page?
No, just makes it. Doesn’t exist on page until you use the append method.
How do you add an element as a child to another element?
appendChild( ) method
What do you pass as the arguments to theelement.setAttribute( )method?
Two arguments: name and value (both as strings)
Name two ways to set theclassattribute of a DOM element.
Element.setAttribute( )
Element.className
What is thetextContentproperty of an element object for?
To get text content or to set the text content of an element
What steps do you need to take in order to insert a new element into the page?
createElement and then append it
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
Defining a function allows for reusability so you don’t have to write the function over and over. Defined functions are also easy to test.