LearningFuze Mod 1 - Dom Query Flashcards

1
Q

Why do we log things to the console?

A

To check and debug our code

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

What is a “model”?

A

Its showing an example of something

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

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

A

Document Node

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

What is the word “object” referring to in the phrase Document Object Model?

A

A collection of objects in javascript

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

What is a DOM Tree?

A

It represents html objects in the nodes

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

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

A

Documents query selector, and get element by ID

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

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

A

getElementsByClassName()

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

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

A

When you need to work with an element more than once, you should use a variable for that query, it also saves time

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

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

A

the dir method

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

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

A

The HTML must be read before the script, or the webpage will read the script first

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

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

A

It takes a CSS selector but instead of a string it returns the HTML element and what it’s holding

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

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

A

it takes any CSS selector and it returns a static Node list

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

Why do we log things to the console?

A

To check and debug our code

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

What is the purpose of events and event handling?

A

An event indicates an action taking place, and the event handle deals with the event

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

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

A

No

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

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

A

the addEventListener method

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

What is a callback function?

A

it calls and argument in another function

18
Q

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

A

the event object

19
Q

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

A

It is the element that targets the event

20
Q

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

The first code has the callback function and the second code is just being called.

21
Q

What is the className property of element objects?

A

Is a property that allows us to access or set value of the class for that element

22
Q

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

A

using the className property

23
Q

What is the textContent property of element objects?

A

Allows you to update the text content of the element you are working with

24
Q

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

A

Inner html or text content

25
Q

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

A

Not always

26
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

It would be more complicated because I would have to search each time what we can use to reference a certain number

27
Q

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

A

It would make us dependent on information stored on the DOM for our Javascript

28
Q

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

A

It does not do it

29
Q

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

A

You would use the appendChild method

30
Q

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

A

Name and value

31
Q

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

A

create the element, and then append it

32
Q

What is the textContent property of an element object for?

A

It sets or denotes the text content

33
Q

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

A

Can use the set attribute method and class name with is a property

34
Q

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

A

Pass in arguments and the second one is adding it to an event listener

35
Q

What is the event.target?

A

It is the point of interaction

36
Q

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

A

by bubbling

37
Q

What does DOM element property tell you what type of element it is?

A

The tag name property

38
Q

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

A

for the argument it takes selectors and for the returns itself or the matching ancestor and if it doesn’t return an ancestor it will return null

39
Q

How can you remove an element from the DOM?

A

By using the remove method

40
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

By adding to the parent element