DOM 1 Flashcards
Why do we log things to the console?
to see what’s going on in the code and help with debugging
What is a “model”?
replica. when browser loads a web page, it creates a model of the page in memory.
Which “document” is being referred to in the phrase Document Object Model?
HTML document.
What is the word “object” referring to in the phrase Document Object Model?
javascript object.
What is a DOM Tree?
the way in which the browser should structure the model. (Model of a web page made of objects)
Give two examples of document methods that retrieve a single element from the DOM.
Document.querySelector(), Document.getElementById()
Give one example of a document method that retrieves multiple elements from the DOM at once.
Document.querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
to save time and be able to access the variable multiple times.
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?
Javascript is often used to manipulate DOM and add new functionality to the webpage. If tag is not added at end of the tag, DOM may not be ready by that time, thus preventing javascript to work on it, leading to unknown behaviors.
What does document.querySelector() take as its argument and what does it return?
it takes CSS selector as parameter and returns the first element within the document that matches the specified selector.
What does document.querySelectorAll() take as its argument and what does it return?
it takes CSS selector as parameter and returns non-live NodeList containing one element object for each element that matches at least one of the specified selectors or an empty NodeList in case no matches.
Why do we log things to the console?
to see what’s going on in the code and help with debugging
What is the purpose of events and event handling?
Event handlers can be used to handle and verify user input, user actions, and browser actions:
- Things that should be done every time a page loads
- Things that should be done when the page is closed
- Action that should be performed when a user clicks a button
- Content that should be verified when a user inputs data
Are all possible parameters required to use a JavaScript method or function?
no