DOM Flashcards
Why do we log things to the console?
to check the result of element
What is a “model”?
representation of an actual thing
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?
JavaScript
What is a DOM Tree?
tree data structure of HTML page
Give two examples of document methods that retrieve a single element from the DOM.
queryselector & getElementById
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 the result again
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?
so that dom element gets loaded before javascript try to get elements
What does document.querySelector() take as its argument and what does it return?
selector element and result first match
What does document.querySelectorAll() take as its argument and what does it return?
selector element and result is all-match
Why do we log things to the console?
to debugging
What is the purpose of events and event handling?
to perform some action base on user action
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 the className property of element objects?
its use to get and update class name of element
How do you update the CSS class attribute of an element using JavaScript?
get element using className
What is the textContent property of element objects?
It can get or update the element text content
How do you update the text within an element using JavaScript?
using element.textContetent = value
is the event parameter of an event listener callback always useful?
No
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
more complicated
Why is storing information about a program in variables better than only storing it in the DOM?
to get specific element property multiple time and going through dom each time is not effective its better to store it to the variable
Does the document.createElement() method insert a new element into the page?
no it does not
How do you add an element as a child to another element?
parentName.appenchild(childName)
What do you pass as the arguments to the element.setAttribute() method?
name of the attribute
What steps do you need to take in order to insert a new element into the page?
createElement() put it into variable
createTextNode() to create text
appendChild where to put the element
What is the textContent property of an element object for?
to get or add text content to the element
Name two ways to set the class attribute of a DOM element.
set attribute and class name
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
reuse the code
What is the event.target?
its return where the event occure
Why is it possible to listen for events on one element that actually happen its descendent elements?
bcas it carried forward to its ancestors
What DOM element property tells you what type of element it is?
tagName property
What does the element.closest() method take as its argument and what does it return?
it take css selector and return the closest one
How can you remove an element from the DOM?
remove() method on DOM element
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
add it to one layer above and listen to that event
What is the event.target?
shows where event was trigger
What is the affect of setting an element to display: none?
remove from document flow
What does the element.matches() method take as an argument and what does it return?
boolean value
How can you retrieve the value of an element’s attribute?
getAttribute() method
At what steps of the solution would it be helpful to log things to the console?
every step
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
then need to write event for each element
If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
we have to write if condition for each node