DOM & JavaScript Flashcards
Why do we log things to the console?
look at values of variables and double check functions
Which “document” is being referred to in the phrase Document Object Model?
refering to the HTML document
What is the word “object” referring to in the phrase Document Object Model?
refering to JavaScript objects
What is a DOM Tree?
Model of web page consisting of all elements used on web page
Give two examples of document methods that retrieve a single element from the DOM.
queryElementById( ) & querySelector( )
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementById( ) & querySelectorAll( )
Why might you want to assign the return value of a DOM query to a variable?
for future references if needed to be used more than once
What console method allows you to inspect the properties of a DOM element object?
console.dir( )
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
since the the document loads from top to bottom
What does document.querySelector() take as its argument and what does it return?
takes in a DOM string and returns a string of a css selector
What does document.querySelectorAll() take as its argument and what does it return?
takes in a css selector and returns a node list
Does the document.createElement() method insert a new element into the page?
No, just makes elements
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?
attribute and value ex: (“class”, “contianer”)
What steps do you need to take in order to insert a new element into the page?
- create element 2. give content 3. add it to the dom