dom-creation Flashcards
Does the document.createElement() method insert a new element into the page?
no.
How do you add an element as a child to another element?
you can use the appendChild() method.
What do you pass as the arguments to the element.setAttribute() method?
the first one is the name of the attribute, and the second one is the value(a string) for the attribute.
What steps do you need to take in order to insert a new element into the page?
there are three steps, first create a new element using the createElement() method. step 2 is to give it content using createTextNode()(this step is optional), step 3 is to add it to the DOM by using appendChild() method.
What is the textContent property of an element object for?
to get the text content of an element.
Name two ways to set the class attribute of a DOM element.
setAttribute() method and the className property
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
it saves a lot of work creating html structure and its content. and it’s easier to control the content .