DOM Flashcards
(45 cards)
Why do we log things to the console?
To make sure the code is running correctly and see the data
What is a “model”?
A small representation of something we’re going to build generally
Which “document” is being referred to in the phrase Document Object Model?
The entire HTML document
What is a DOM Tree?
Its a collection of objects that makes up the document
Give two examples of document methods that retrieve a single element from the DOM.
getElementById and querySelector()
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?
In case you need to use the same 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?
Because we need to load HTML first. or else it will run before the HTML, which we wont be able to query the DOM.
What does document.querySelector() take as its argument and what does it return?
selector. It will return the first element in the dom that matches it.
What does document.querySelectorAll() take as its argument and what does it return?
Selector. Returns a node list or a collection of all the elements that match that selector.
What is the word “object” referring to in the phrase Document Object Model?
The document object. we can check it on console.dir()
What is the purpose of events and event handling?
Have some type of response to when a user interacts with the web page
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()
What is a callback function?
A callback function is a function passed into another function as an argument
What object is passed into an event listener callback when the event fires?
Event object
What is the event.target?
Target its what the user interacted with. For example, the button ‘Click Me’
It targets the element that triggered the event.
What is the difference between these two snippets of code?element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
second: handleClick is being called. and the return value of handleClick will be substituted for the argument. handleClick() is being called without argument, there is no event object, there is no access to that. and its being called right when the code starts running because of (), no matter what, its going to try to call the function every time. so its going to pass ‘undefined’ as the argument because we’re not returning anything inside handleClick
What is the className property of element objects?
Its a property that stores the class names for that particular element and it can be updated
How do you update the CSS class attribute of an element using JavaScript?
className and the assignment operator
What is the textContent property of element objects?
represents the text content of the main element and its descendants.
How do you update the text within an element using JavaScript?
.textContext and assignment operator
Is the event parameter of an event listener callback always useful?
No. Because sometimes we’re not making use of the event inside the function. But the event object its still there and its always available.