DOM Flashcards
Why do we log things to the console?
To see if there are any bugs in the code. The browser will print errors and warnings as they occur in the JS code.
What is a “model”?
a representation of something.
Which “document” is being referred to in the phrase Document Object Model?
HTML
What is the word “object” referring to in the phrase Document Object Model?
The datatype object in the JS language
DOM = recreation of HTML document in the form of a javascript object.
What is a DOM Tree?
A model of a web page. It is stored in the browser’s memory. An element plus all its configurations plus all of its contents
Give two examples of document methods that retrieve a single element from the DOM.
getElementById(), querySelector()
only need to use querySelector().
Why might you want to assign the return value of a DOM query to a variable?
If the script needs to use the same elements more than once.
What console method allows you to inspect the properties of a DOM element object?
Dir method
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
It gives the HTML time to load before the javascript load. Things load from top to bottom if the script is located at the top of the body, the JS is looking for code that hasn’t loaded yet.
What does document.querySelector() take as its argument and what does it return?
Uses a CSS selector and returns the first matching element.
What does document.querySelectorAll() take as its argument and what does it return?
Uses a CSS selector to select all matching elements. Outputs a list of nodes.
What is the purpose of events and event handling?
To make the web page more interactive. When something happens on the web page a script can respond by updating the content of 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 () method.
What is a callback function?
A function passed into another function as an argument which is then invoked inside the outer function to complete some kind of action.
What object is passed into an event listener callback when the event fires?
An object with a huge set of properties and values that describes the event and we can change the values in the object if we want to adjust it. Since we cant pass through arguments, JS provides us with an object of everything that event is doing.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
A reference to the object onto which the event was dispatched. The element where the event originated from.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
1 ) add.EventListener will receive the arguments: string ‘click’ and a function definition for handleClick.
2) add.EventListener will receive the arguments: string ‘click’ and the return value from handleClick.
What is the className property of element objects?
Sets the value of the class attribute of the specified element.
How do you update the CSS class attribute of an element using JavaScript?
.className property.
What is the textContent property of element objects?
It allows you to update the text that is in the containing element.