DOM Flashcards
Why do we log things to the console?
Show check if our code is doing what its supposed to be doing; debugging
What is a “model”?
A representation of HTML on a webpage
Which “document” is being referred to in the phrase Document Object Model?
The document is the web page
What is the word “object” referring to in the phrase Document Object Model?
The different parts that the web page is made of
What is a DOM Tree?
A model of a web page made out of objects, with each object representing a different part of the web page
Give two examples ofdocumentmethods that retrieve a single element from the DOM.
querySelector method, getElementById method
Give one example of adocumentmethod that retrieves multiple elements from the DOM at once.
getElementsByClassName method
Why might you want to assign the return value of a DOM query to a variable?
You may need to work with the element more than once, so it makes it easily accessible
Whatconsolemethod allows you to inspect the properties of a DOM element object?
console.dir()
Why would atag 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 doesdocument.querySelector()take as its argument and what does it return?
It takes a selector for an element as the argument, and returns the first element on the document with that specified selector
What doesdocument.querySelectorAll()take as its argument and what does it return?
It takes a selector for an element and returns a Nodelist of all the elements on the page that match that selector
Why do we log things to the console?
To show that the code is doing what its supposed to be doing and to debug it
What is the purpose of events and event handling?
It gives a response to user input.
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 function that is passed into another function as an argument
What object is passed into an event listener callback when the event fires?
The event object
What is theevent.target? If you weren’t sure, how would you check? Where could you get more information about it?
It returns the element that triggered the event. You can log it to the console to find more information about it
What is theclassNameproperty of element objects?
It lets you set a new value for the class attribute for an element
How do you update the CSS class attribute of an element using JavaScript?
Have a new class name assigned to the className property of your chosen element object
What is thetextContentproperty of element objects?
It allows you to get all the text content of that element and update it also
How do you update the text within an element using JavaScript?
Have some string text assigned to the textContent property of you chosen element object
Is theeventparameter of an event listener callback always useful?
No