DOM Flashcards

1
Q

Give two examples of document methods that retrieve a single element from the DOM.

A

querySelector() and getElementById()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

QuerySelectorAll()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why might you want to assign the return value of a DOM query to a variable?

A

Its easier to find if the browser needs to use the same elements more than once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What console method allows you to inspect the properties of a DOM element object?

A

Console.dir()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why would a tag need to be placed at the bottom of the HTML content instead of at the top?

A

So it can create a model after the document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does document.querySelector() take as its argument and what does it return?

A

Selectors, and it returns an HTML element object representing the first element in the document that matches the specified set of CSS selectors, or null is returned if it doesn’t find a match.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does document.querySelectorAll() take as its argument and what does it return?

A

Selectors and it returns a nodelist or an empty nodelist if it doesn’t find any matches.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What method of element objects lets u set up a function to be called when a specific type of event occurs?

A

the eventTarget.addeventListener();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a callback function

A

A function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is the object passed into an event listener callback when the event fires?

A

The event object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the event.target? if you weren’t sure, how would you check? Where could you get more information about it?

A

The target property of the event interface which references the object onto which the event was dispatched. Console.log(), MDN?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between these two snippets of code?element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())

A

the first waits for the event to happen then fires the function and the second one fires the event when the page gets loaded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what do [ ] square brackets mean in function and method syntax documentation?

A

optional parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Does the document.createElement() method insert a new element into the page?

A

No it just creates an element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you add an element as a child to another element?

A

appendChild() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What do you pass as the arguments to the element.setAttribute() method?

A

name and value

17
Q

What steps do you need to take in order to insert a new element into the page.

A

Create the element create elements nested into the outer element and append them to said element.

18
Q

What is the text content property of an element object for?

A

To retrieve or replace the text content in the dom element

19
Q

Name two ways to set the class attribute of a DOM element

A

setAttribute(); and .className

20
Q

What are two advantages of defining a function to do create something ( like the work of creating a DOM tree)?

A

you dont have to go into the HTML document to create it and everything is all in one spot?

it lets you use it where ever you want and you can reuse it.

21
Q

what is the event.target?

A

The target property of the event interface which is reference to the object onto which the event was dispatched.

22
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

because of event bubbling.

23
Q

what DOM element property tells you what type of element it is?

A

element.tagName

24
Q

What does the element.closest() method take as its argument and what does it return?

A

the closest method returns the first encounter ancestor element that matches the selector provided

25
Q

How can you remove an element from the DOM?

A

the remove() method

26
Q

If you want to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

By just targeting the parent element and putting it on the element that holds the element.

27
Q

What is the affect of setting an element to display: none?

A

it disappears

28
Q

what does the element.match() method take as an argument and what does it return

A

Selector string as an argument

29
Q

at what steps of the solution would it be helpful to log things to the console?

A

every step of the way

30
Q

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?

A

we’d have to add an event listener to each element.

31
Q

if you didn’t use a loop to continually show or hide the views in the page, how would your javascript code be written instead?

A

you’d need a conditional for each view.

32
Q

How can you retrieve the value of an elements attribute?

A

getAttribute()