JavaScript DOM Flashcards

1
Q

What event is fired when a user places their cursor in a form control?

A

focus

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

What event is fired when a user’s cursor leaves a form control?

A

blur

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

What event is fired as a user changes the value of a form control?

A

input

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

What event is fired when a user clicks “submit” button within a <form>?

A

submit

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

What does the event.preventDefault() method do?

A

Prevents the page from automatically reloading after the form has been submitted and every events default behavior

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

What does submitting a form without event.preventDefault() do?

A

Reload the page and the form

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

What property of a form element object contains all of the form’s controls.

A

.elements

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

What property of a form control object gets and sets its value?

A

.value

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

What is one risk of writing a lot of code without checking to see if it works so far?

A

Makes it harder to debug

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

What is an advantage of having your console open when writing a JavaScript program?

A

You get to keep track of everything

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

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

A

The attribute followed by the attribute value

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

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

A

createElement()
createTextNode()
appendChild()

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

createElement()
appendChild()

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

To change the text content of an element or add

17
Q

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

A

element.setAttribute()
element.className()

18
Q

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

A

Reusability

19
Q

What is the event.target?

A

It’s a reference to whatever object it interacted with

20
Q

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

A

Event Bubbling

21
Q

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

A

event.target.tagName

22
Q

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

A

Takes a class name as an argument and returns the closest element to the method’s element with the argument class name

23
Q

How can you remove an element from the DOM?

A

With the element.remove() method

24
Q

If you wanted to insert a new clickable DOM element into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

By appending that new element to a parent element that already has an event listener to it

25
Q

What is the event.target?

A

A reference to the object onto the event being fired

26
Q

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

A

It’ll be removed from the page

27
Q

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

A

It takes a selector as the argument and returns either true or false if that selector matches the element

28
Q

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

A

getAttribute() method

29
Q

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

A

On all steps

30
Q

If you were to add another tab and view to your HTML, but you didn’t use even delegation, how would your JavaScript code be written instead?

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