DOM Flashcards

1
Q

What is the purpose of events and event handling?

A

To notify code of “interesting changes” that may affect code execution.

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

Are all possible parameters required to use a JS method or function?

A

No

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

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

A

addEventListener()

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

What is a callback function?

A

A function that is passed into another function as an argument.

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

What object is passed into an eventListener callback when the event fires?

A

An event

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

What is the |event.target|? If you weren’t sure, how would you check?

A

The target of the event being listened to, and console.log it

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

What is the |className| property of an element’s object?

A

Gets and sets the value of the class attribute of the specified element

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

How do you update the CSS class attribute of an element using JS?

A

class.add() / class.remove()

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

What is the |textContent| property of element objects?

A

Represents the text content of the element

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

How do you update the text within an element using JS?

A

element.textContent = ‘content’

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

Is the |event| parameter of an eventListener callback always useful?

A

Yes

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

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

A

No

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

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

A

appendChild()

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

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

A

name of attribute, value of attribute
ex: (‘class’, ‘pokemon’)

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

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

A

Query the DOM for the parent element, then create a new element, then appendChild the new element to the parent element.

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

What is the |textContent| property of an element object for?

A

Specifically create raw text

17
Q

Name 2 ways to set the class attribute of a DOM element.

A

set.className / .classList

18
Q

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

A

Because of event bubbling

19
Q

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

A

event.target.tagName

20
Q

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

A

Takes a selector and returns closest ancestor

21
Q

How can you remove an element from the DOM?

A

.remove()