JavaScript DOM Flashcards
Why do we log things to the console?
To make sure code is working as intended.
What is a “model”?
a type of ‘recreation” of an html page, stored in memory.
Which “document” is being referred to in the phrase Document Object Model?
The document node of the DOM tree.
What is the word “object” referring to in the phrase Document Object Model?
The DOM is called an object model because the model (the DOM tree) is made of objects.
What is a DOM Tree?
a model of a webpage made of objects.
Give two examples of document methods that retrieve a single element from the DOM.
getElementById(‘id’), querySelector(‘’)
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll(‘element’), getElementByClass(‘’)
Why might you want to assign the return value of a DOM query to a variable?
when you want to work with the same selection of elements more than once.
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?
The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.
What does document.querySelector() take as its argument and what does it return?
css selector, returns only the first of the matching elements.
What does document.querySelectorAll() take as its argument and what does it return?
css selector, returns a nodeList unless only one.
Why do we log things to the console?
To make sure our code is working as intended.
What is the purpose of events and event handling?
The event handling runs desired code when the event happens.
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?
addEventListener() method.
What is a callback function?
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
What object is passed into an event listener callback when the event fires?
the event object.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The specific html element that cause the event to occur. You can check MDN for more information.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
the first one will run when the event fires.
the second one will run as the page loads, and the result will be called when the event fires.
What is the className property of element objects?
tells us the current class of the object and allows us to update it.
How do you update the CSS class attribute of an element using JavaScript?
getElementByClass()
What is the textContent property of element objects?
tells us the current text content and allows us to update it.