DOM Flashcards
Why do we log things to the console?
We log things as a console both to make sure that the main.js file is interacting with the html file and so that we as developers can test and track values (debugging)
What is a “model”?
A recreation of something (generally not 1:1 recreation)
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 JavaScript object data type
What is the DOM?
A JavaScript object that is modeling the contents of an HTML document that is loaded into the browser
What is a DOM Tree?
The DOM tree is a list of objects/nodes that branch off of the document node. It is made up of the different elements, attributes, and text nodes in an HTML document. It is an element plus all of its content and all of its configurations.
Give two examples of document methods that retrieve a single element from the DOM.
document. getElementbyID(‘id’);
document. querySelector(‘css selector’);
Give one example of a document method that retrieves multiple elements from the DOM at once.
document. querySelectorAll(‘css selector’);
document. getElementsByClassName(‘class’);
document. getElementsByTagName(‘tag name’);
Why might you want to assign the return value of a DOM query to a variable?
In case you need to re-use that value of a DOM query multiple times
What console method allows you to inspect the properties of a DOM element object?
console.dir( ); [ dir is short for directory]
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
Because we want to load the content of the HTML document first?
What does document.querySelector() take as its argument and what does it return?
document.querySelector( ); takes a css selector as it’s argument (in a string) and returns the first element that matches the selector
What does document.querySelectorAll() take as its argument and what does it return?
document.querySelectorAll( ); takes a css selector as it’s argument (in a string) and returns all elements with that css selector (Node List)
Why do we log things to the console?
We log things as a console both to make sure that the main.js file is interacting with the html file and so that we as developers can test and track values (debugging)
What is the purpose of events and event handling?
Events are a way to let us know when an event occurs (usually when a user interacts with the page) and event handling is our way of preparing a response when the event occurs
Are all possible parameters required to use a JavaScript method or function?
No, there are some parameters that are optional