DOM Flashcards

1
Q

only use?

A

querySelector(‘xxx’)
querySelectorAll(‘xxx’)

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

callback

A

share the value of one function with another

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

event handler

A

the function write for event (no return in here because only event will get the value, you will never call it by yourself)

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

What is a DOM Tree?

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

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

A

html document

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

querySelector
querySelectorAll

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

querySelectorAll

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

easy to reuse

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

console.log
console.dir

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
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

element in dom

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

all () element in dom

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

for moniter user interaction, when fired, run function

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, 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
17
Q

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

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
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 event property returns the element that triggered the event. The target property gets the element on which the event originally occurred, opposed to the currentTarget property, which always refers to the element whose event listener triggered the event.

19
Q

What is the className property of element objects?

A

The className property of the Element interface gets and sets the value of the class attribute of the specified element.

20
Q

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

A

$xxx
$xxx.className = ppp

21
Q

What is the textContent property of element objects?

A

The textContent property sets or returns the text content of the specified node, and all its descendants.

22
Q

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

A

Use the textContent property to change the text of a div element, e.g. div. textContent = ‘Replacement text’ . The textContent property will set the text of the div to the provided string, replacing any of the existing content.

23
Q

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

A

Defining the event as a parameter of your handler function is optional but, sometimes (most times), it is useful for the handler function to know about the event that happened.

24
Q

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

A

no. it only creat

25
Q

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

A

ae.appendChild(xxx)

26
Q

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

A

ement.setAttribute(‘attribute type’, ‘attribute value’)

27
Q

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

A

creat node element
grab the parent element with querySelector
append node to parent

28
Q

What is the textContent property of an element object for?

A

set the text value for its parent node

29
Q

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

A

setAttribute
className

30
Q

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

A

avoid repeat code

31
Q

What is the event.target?

A

where the event started

32
Q

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

A

event buble

33
Q

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

A

event.target.tagName

34
Q

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

A

parent

35
Q

How can you remove an element from the DOM?

A

delete

36
Q

What is the event.target?

A

the origin source where event occur

37
Q

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

A

disappear

38
Q

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

A

css selector as string value, return boolean. true means match , false means not match

39
Q

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

A

getAttribute

40
Q

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

A

everytime

41
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

creat individual eventlisener for each part

42
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
43
Q

data-xxx attribute

A

store a meaningful name for connect dom and js

44
Q

dataset.xxx

A

shorthand of getAttribute for data- attribute