JavaScript DOM Flashcards
Why do we log things to the console?
Be aware of what we are doing, in DOM querys to make sure you know what element is selected.
What is a “model”?
Its a recreation
Which “document” is being referred to in the phrase Document Object Model?
The HTML document we are working with.
What is the word “object” referring to in the phrase Document Object Model?
All the elements which are objects
What is a DOM Tree?
A collection of all elements of the DOM
Give two examples of document methods that retrieve a single element from the DOM.
getelementbyid
queryselector
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 reuse an element quicker
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 HTML needs to be loaded (parsed) first so we can search for HTML elements.
What does document.querySelector() take as its argument and what does it return?
It takes a CSS-selector as a string. returns the first match
What does document.querySelectorAll() take as its argument and what does it return?
Takes a CSS-selector.
Returns a node list of all elements that match.
Why do we log things to the console?
So we know where we make errors and bugs, and dont have to search a page of code.
What is the purpose of events and event handling?
Events and event handling allow us to make pages interactive.
Are all possible parameters required to use a JavaScript method or function?
No. there are many optional parameters.
What method of element objects lets you set up a function to be called when a specific type of event occurs?
the addeventlistener method.
What is a callback function?
a function being called that is declared outside the current function.
What object is passed into an event listener callback when the event fires?
The listener object generally a function
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The event.target shows us what the event fired on ie. what button was clicked. and you can and should console log it while building your handlers.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
One is passing the function as a parameter and the other called the function and passes the result as the parameter.
What is the className property of element objects?
it accessing the class atributes of the element
How do you update the CSS class attribute of an element using JavaScript?
with element.className = new class name
What is the textContent property of element objects?
it is all the text
How do you update the text within an element using JavaScript?
with the el.textContent property