JAVASCRIPT - DOM Flashcards
Why do we log things to the console?
to get information and verify things
What is a “model”?
It’s a representation of something else
Which “document” is being referred to in the phrase Document Object Model?
HTML document
What is the word “object” referring to in the phrase Document Object Model?
data type
What is a DOM Tree?
element + content + configuration
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() –> only use this!!!!
Why might you want to assign the return value of a DOM query to a variable?
to utilize it repeatedly in the future - you could put it in a variable so that you don’t have to search for it over and over as the user uses your web
What console method allows you to inspect the properties of a DOM element object?
console.dir
dir = directory
dir ==> it shows EVERYThing of that specific element
console.log ==> make it all pretty vs directory
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
HTML document loads from top to bottom. It needs to load to the document before it runs the document.querySelector or else it will get a null
What does document.querySelector() take as its argument and what does it return?
takes an argument of a string of that CSS selector and the return value is the first element that matches the selector so the second and third will not be returned.
What does document.querySelectorAll() take as its argument and what does it return?
takes a string as an argument returns NodeList - examples of array-like object
What is the purpose of events and event handling?
events & events handling–> we can respond to certain things –> gives interactivity
we are preparing for the response we must give when an user does certain action
event handler –> set of data of what needs to be done
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 function taking a function definition and giving and moving it around to others
it’s like sharing a recipe with a friend
What object is passed into an event listener callback when the event fires?
event object is like bunch of data that will show what can happen
bunch of data is pushed into
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
where it holds the element that it originated from
you could go to MDN to research more about it
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick) vs element.addEventListener(‘click’, handleClick())
1st one – passing handleClick as a variable value which is a function
2nd one – we are calling an argument –> second one is WRONG. wont do it
What is the className property of element objects?
To re-label the class name
value of an attribute of HTML element
How do you update the CSS class attribute of an element using JavaScript?
class.className = “class name (separate by space) class name”