DOM Flashcards
1
Q
- Which “document” is being referred to in the phrase Document Object Model?
A
The HTML document
2
Q
- What is the word “object” referring to in the phrase Document Object Model?
A
- The data type object in JavaScript
3
Q
What is a DOM tree?
A
- The DOM tree is the model of the HTML document stored as an object in JavaScript
4
Q
- Give two examples ofdocumentmethods that retrieve a single element from the DOM.
A
- Document.querySelector();
* Select element by id
5
Q
- Give one example of adocumentmethod that retrieves multiple elements from the DOM at once.
A
- document.querySelectorAll();
6
Q
- Why might you want to assign the return value of a DOM query to a variable?
A
- So you can work with an element more than once
7
Q
- Whatconsolemethod allows you to inspect the properties of a DOM element object?
A
- console.dir();
8
Q
- Why would ascript tag need to be placed at the bottom of the HTML content instead of at the top?
A
- The browser needs to parse all of the elements in the HTML page before the JS code can access them.
9
Q
- What doesdocument.querySelector()take as its argument and what does it return?
A
- A string, Css selector and it returns the first matching elements
10
Q
- What doesdocument.querySelectorAll()take as its argument and what does it return?
A
- A string, Css selector to select all matching elements and returns a NodeList
11
Q
Difference between Number.isNaN(); and isNan();
A
Number.isNaN returns true when the argument is a number and is NaN.
isNaN converts to a number and returns true when the resulting value is NaN
12
Q
- What is the purpose of events and event handling?
A
They make our apps do stuff!
13
Q
- Are all possible parameters required to use a JavaScript method or function?
A
No
14
Q
- What method of element objects lets you set up a function to be called when a specific type of event occurs?
A
.addEventListener
15
Q
callback function
A
a function definition being passed in as an argument
16
Q
- What object is passed into an event listener callback when the event fires?
A
The target of the object
17
Q
- What is theevent.target? If you weren’t sure, how would you check?
A
You can check in your browser/ console.
18
Q
What is the difference?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
A
handleClick());
fires immediately and messes up the function when button clicks.