DOM Flashcards
Why do we log things to the console?
our investigative mechanism, communicate with the computer and get information about it
What is a “model”?
a representation of how something may look
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?
JavaScript Object
What is a DOM Tree?
an element plus all of it’s content and it’s configuration, plus it’s children and their content/configurations
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?
so that you can access it again easily
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?
because it needs to parse the entire document first, which means loading all the html elements. The entire content of the html document needs to be created before you can do anything with it.
What does document.querySelector() take as its argument and what does it return?
takes a css selector as a string, and the return value is the first element that javascript finds in the document that matches the css selector you passed through. return is object.
What does document.querySelectorAll() take as its argument and what does it return?
takes a string as it’s argument and returns a nodelist which is an array-like object but isn’t necessarily an array. return is a nodelist, which is still one object.
Why do we log things to the console?
for debugging, investigative mechanism
What is the purpose of events and event handling?
the purpose is to prepare for a possible action the user can take and do something in response. When this happens, do this thing.
Gives the page interactivity
Are all possible parameters required to use a JavaScript method or function?
Not necessary at all times, there are optional parameters
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’s being passed into another function as an argument
What object is passed into an event listener callback when the event fires?
the event object, which is a bunch of information about what happened, on what it happened.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
A property that holds the element where the event originated from. To be sure what it is then you can: console.log(event.target);
the property that’s being selected by query can be different from the event.target - as that one tells you where it originated from. So it could be from an element within the element you’ve selected using queryselector. (remember bubbling)
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
the first is passing the handleClick function as a callback, whereas the second one is calling it right there and then - which doesn’t work.
What is the className property of element objects?
the className property holds the value of the classname attribute of an html element
How do you update the CSS class attribute of an element using JavaScript?
object.className = // it would be a string and any number of classes separated by spaces e.g. “blue-text underline”