DOM Flashcards

1
Q

Why do we log things to the console?

A

To make sure the code is running correctly and see the data

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

What is a “model”?

A

A small representation of something we’re going to build generally

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

The entire HTML document

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

What is a DOM Tree?

A

Its a collection of objects that makes up the document

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

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

A

getElementById and querySelector()

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

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

A

Document.querySelectorAll()

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

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

A

In case you need to use the same elements more than once

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

Why would a

 tag need to be placed at the bottom of the HTML content instead of at the top?
A

Because we need to load HTML first. or else it will run before the HTML, which we wont be able to query the DOM.

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

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

A

selector. It will return the first element in the dom that matches it.

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

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

A

Selector. Returns a node list or a collection of all the elements that match that selector.

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

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

A

The document object. we can check it on console.dir()

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

What is the purpose of events and event handling?

A

Have some type of response to when a user interacts with the web page

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

What is a callback function?

A

A callback function is a function passed into another function as an argument

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

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

A

Event object

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

What is the event.target?

A

Target its what the user interacted with. For example, the button ‘Click Me’
It targets the element that triggered the event.

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

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

A

second: handleClick is being called. and the return value of handleClick will be substituted for the argument. handleClick() is being called without argument, there is no event object, there is no access to that. and its being called right when the code starts running because of (), no matter what, its going to try to call the function every time. so its going to pass ‘undefined’ as the argument because we’re not returning anything inside handleClick

20
Q

What is the className property of element objects?

A

Its a property that stores the class names for that particular element and it can be updated

21
Q

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

A

className and the assignment operator

22
Q

What is the textContent property of element objects?

A

represents the text content of the main element and its descendants.

23
Q

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

A

.textContext and assignment operator

24
Q

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

A

No. Because sometimes we’re not making use of the event inside the function. But the event object its still there and its always available.

25
Q

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

A

Easier to access

26
Q

Difference between innerText and textContent

A

innerText= will only be able to pull text from elements that are currently visible
textContent does not care. It will still let you access those things.

27
Q

What does the transform property do?

A

It allows you to modify the way that an element displays on a page.

28
Q

Give four examples of CSS transform functions.

A

rotate, scale, skew, or translate

29
Q

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

A

No. It just creates an element.

30
Q

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

A

appendChild() method;

31
Q

Difference between append() and appendChild()

A

With append, we can append multiple children at once. So we can pass multiple arguments in and it will append all into the same level.

32
Q

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

A

name of attribute and value

33
Q

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

A

createElement, give a content(textContent), and append it to the DOM (appendChild/append)

34
Q

What is the textContent property of an element object for?

A

It allows to create a text node and assign a text into an element
If we reassign the text content of an element, it will destroy any children and any text that element has.

35
Q

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

A

setAttribute, className, and classList

36
Q

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

A

repeatability, and visually more pleasing

37
Q

Give two examples of media features that you can query in an @media rule.

A

background color, min-width, hover

38
Q

Which HTML meta tag is used in mobile-responsive web pages?

A

Viewport meta tag

39
Q

What is the event.target?

A

its not the element that has the event listener, its the element which dispatched the event, which was interacted with. even when its the child of a parent. ex: when we click on an element

40
Q

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

A

If there was an event listener that was put on the parent, it would be able to detect any events that happen on its children. Its because those events will bubble up. So if the ul has an event listener and we click on its children, the event listener will fire.

41
Q

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

A

event.target.tagName/.-> will always return an element tag
there’s also a similar property called nodeName-> ocasionally may give something other than an element. and thats because node can be text node, white space nodes, element…

42
Q

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

A

Argument: selector. Return value: The closest ancestor Element or itself, which matches the selectors. If it does have any ancestor, it will return null

43
Q

How can you remove an element from the DOM?

A

element.remove() method

44
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 using the bubbling, we can put an event listener on the parent, and then anything that happens to its children it will catch.

45
Q

What is event.current.target?

A

It will always refer to this specific element that has the event.listener