DOM Javascript Flashcards

1
Q

What is the purpose of events and event handling?

A

events check for events that happen and event handling fires it

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

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

A

optional arguments

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

function that gets put into another function as argument and runs

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

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

A

event object which has properties that tell us it’s current status or data

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? Where could you get more information about it?

A

event.target is the target element

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

Which “document” is being referred to in the phrase Document Object Model?

A

HTML document and elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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
9
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
10
Q

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

A

so that we can reuse it later

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
Q

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

A

css selector in string notation

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

What is the className property of element objects?

A

it returns name of class

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

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

A

use .className

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

What is the textContent property of element objects?

A

it returns the content of text

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

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

A

textContent, innerHTML and innerText

17
Q

Is the event parameter of an event listener callback always useful?

A

not necessarily

18
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

more complicated

19
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

because we can use it when we want to

20
Q

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

A

No, not until it is appended to existing element on html document

21
Q

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

A

parentElement.appendChild()

22
Q

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

A

class then className

23
Q

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

A

Append created element to existing element on HTML page

24
Q

What is the textContent property of an element object for?

A

Used to get or alter the textContent of the element

25
Q

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

A

setAttribute or manually

26
Q

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

A

Efficiency and consistency

27
Q

What is the event.target?

A

element that is currently interacting with the event fired

28
Q

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

A

element will not be displayed and will be removed from the flow of the document

29
Q

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

A

css selector and returns boolean true if matched

30
Q

How can you retrieve the value of an element’s attribute?

A

getAttribute method

31
Q

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

A

Every necessary step

32
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

It would look alot longer

33
Q

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?

A

It would look alot longer

34
Q

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

A

because of bubbling. The ancestor contains the descendants.

35
Q

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

A

tagName

36
Q

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

A

css selector and returns the closest matching element.

37
Q

How can you remove an element from the DOM?

A

element.remove()

38
Q

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?

A

use event-delegation