DOM Flashcards
Why do we log things to the console?
To check if the value given was as expected.
What is a “model”?
A representation of something.
Which “document” is being referred to in the phrase Document Object Model?
The HTML document.
What is the word “object” referring to in the phrase Document Object Model?
The data type object in javascript.
What is a DOM Tree?
JS Object for an html element including all of its children plus attributes and values for itself and its children.
Give two examples of document methods that retrieve a single element from the DOM.
querySelector and getElementById.
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?
To use the same element more than once.
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?
So the browser can parse all of the elements in the page before the javascript code can access them.
What does document.querySelector() take as its argument and what does it return?
Takes a CSS selector as an argument and returns the first element within the document that matches the selector
What does document.querySelectorAll() take as its argument and what does it return?
Takes a CSS selector as an argument and returns a static NodeList representing the documents elements that match the selector.
Why do we log things to the console?
To check if the value given was as expected.
What is the purpose of events and event handling?
To create a reaction for when something occurs on a webpage.
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener( )
What is a callback function?
A function that is passed into another function as an argument.
What object is passed into an event listener callback when the event fires?
Object with properties that contain all of the data of the event that occurred.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The object onto which the event occurred. Console log / MDN.
What is the className property of element objects?
Gets and sets the value of the class attribute of the element.
How do you update the CSS class attribute of an element using JavaScript?
element.className = ‘ ‘.
What is the textContent property of element objects?
Allows us to get or set text content of an element.
How do you update the text within an element using JavaScript?
node.textContent = ‘ ‘
Is the event parameter of an event listener callback always useful?
no
Why is storing information about a program in variables better than only storing it in the DOM?
To reuse the data and to not mix HTML with Javascript code.