DOM Flashcards
What is a “model”?
The Document Object Model (DOM) is the data representation of the objects that comprise the structure and content of a document on the web.
Which “document” is being referred to in the phrase Document Object Model?
Every element, attribute and piece of text is represented by its own dom node.
What is the word “object” referring to in the phrase Document Object Model?
Each element of the document (which is a node) is represents as an object with its properties
What is a DOM Tree?
Relationships between the document and all of the element nodes and all of their child nodes and text nodes
Give two examples of document methods that retrieve a single element from the DOM.
- getElementById()
- querySelector()
- use this
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
When you need to work with an element more than once, you should use a variable to store the result of this query.
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
The browser needs to parse all the elements in the HTML page before JavaScript code can access them.
What does document.querySelector() take as its argument and what does it return?
String value containing a css selector and returns the first element that contains it
What does document.querySelectorAll() take as its argument and what does it return?
String value that is a css selector and returns a nodelist of all elements found with that selector
What should we start variable names with if it deals with DOM content?
Use a dollar sign $
What is the purpose of events and event handling?
Event are fired to notify code of outside changes that may affect code execution (event handling) like an action that occurs as a result of the user, like a mouse click (event)
Are all possible parameters required to use a JavaScript method or function?
No
What method of element objects lets you set up a function to be called when a specific type of event occurs?
Event Listener