dom-creation Flashcards
Does the document.createElement() method insert a new element into the page?
No, This element node is stored in a variable. When the element node is created, it is not yet part of the DOM tree. It is not added to the DOM tree until step 3
How do you add an element as a child to another element?
appendChild()
What do you pass as the arguments to the element.setAttribute() method?
name
A DOMString specifying the name of the attribute whose value is to be set. The attribute name is automatically converted to all lower-case when setAttribute() is called on an HTML element in an HTML document.
value
A DOMString containing the value to assign to the attribute. Any non-string value specified is converted automatically into a string.
What steps do you need to take in order to insert a new element into the page?
CREATE THE ELEMENT createEl ement () You start by creating a new element node using the createElement() method. This element node is stored in a variable. When the element node is created, it is not yet part of the DOM tree. It is not added to the DOM tree until step 3.
Create TextNode
appendChild
What is the textContent property of an element object for?
textContent gets the content of all elements. The textContent property of the Node interface represents the text content of the node and its descendants.
Name two ways to set the class attribute of a DOM element.
className, setAttribute
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
you can repeatedly call the function, simplifies code, encapsulate the functionaility for rendering the dom tree, can just change the function instead of the rest of the code