Why do we log things to the console?
We log things to the console for debugging purposes.
What is a “model”?
The DOM Tree. Model is a representation/copy of the original.
Which “document” is being referred to in the phrase Document Object Model?
The HTML document is being referred to in the phrase Document Object Model.
What is the word “object” referring to in the phrase Document Object Model?
Each object represents a different part of the page loaded in the browser window.
What is a DOM Tree?
A tree/structure that shows all nodes/chunks of the HTML document.
Give two examples of document methods that retrieve a single element from the DOM.
document. querySelector( )
document. getElementById( )
Give one example of a document method that retrieves multiple elements from the DOM at once.
document. querySelectorAll( )
document. getElementsByTagName( )
document. getElementsByClassName( )
Why might you want to assign the return value of a DOM query to a variable?
We might want to assign a return value of a DOM query to a variable so that it is reusable.
What console method allows you to inspect the properties of a DOM element object?
Short for “directory”.
Why would a «a>script</a>> tag need to be placed at the bottom of the HTML content instead of at the top?
The «a>script</a>> tag needs to be placed at the bottom of the HTML content because the HTML content should load first on the browser.
What does document.querySelector( ) take as its argument and what does it return?
It takes a CSS selector as its argument and returns the first element with that CSS selector.
What does document.querySelectorAll( ) take as its argument and what does it return?
It takes a CSS selector as its argument and returns all elements with that CSS selector.
Why do we log things to the console?
For debugging purposes.
And to check if something is working.
What is the purpose of events and event handling?
The purpose is to add interactive properties to the website for the users.
Add dynamic content.
Ability to have something occur and do something in response.
What method of element objects lets you set up a function to be called when a specific type of event occurs?
What is a callback function?
A callback function is a function being passed around as a value.
What object is passed into an event listener callback when the event fires?
The event object.
The event object includes the target property.
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 is the place/element where the event actually began/occurred. If not sure, we can console.log it and get more information in the console.
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick( ))
A function is being passed in as an argument in the first snippet.
A function is being called as an argument in the second snippet. (This would not work)
What is the className property of element objects?
The className property is the property that holds the class names attached to that element object.
You can update the CSS class attribute of an element by:
$element.className = new class name
What is the textContent property of element objects?
The textContent property is the property that holds the text content attached to that element object/node.
You can update the text within an element by:
$element.textContent = new text content
Is the event parameter of an event listener callback always useful?
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
It would be more complicated.
Why is storing information about a program in variables better than only storing it in the DOM?
It doesn’t have to go to the HTML document to find the data that is desired every time.
Does the document.createElement( ) method insert a new element into the page?
How do you add an element as a child to another element?
What do you pass as the arguments to the element.setAttribute( ) method?
The name of attribute and value of the attribute.
What steps do you need to take in order to insert a new element into the page?
What is the textContent property of an element object for?
It is to set or get the text of that element.
Name two ways to set the class attribute of a DOM element.
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
What is the event.target?
The object for the dom element where the event was fired.
event.target stores the element where the event originated from.
Why is it possible to listen for events on one element that actually happen its descendent elements?
Event bubbling. (Most specific to least specific)
What DOM element property tells you what type of element it is?
What does the element.closest( ) method take as its argument and what does it return?
It takes a CSS selector and it returns the closest ancestor element with the matching selector. (Goes up the tree and look for the element with the matching selector)
How can you remove an element from the DOM?
Add an event listener onto the parent element.