DOM 2 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 event

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 the “submit” button within a ?

A

submit event fires when a is submitted.

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

The Event interface’s preventDefault() method tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.

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

by default, on submission of a form, the page will redirect and refresh. The biggest reason that this becomes a problem is that if you wanted to do anything with that information later on, you can’t.

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

The HTMLFormElement property elements returns an HTMLFormControlsCollection listing all the form controls contained in the element.

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

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

A

value property

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

it will be very difficult to debug later on in code.

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

to catch errors early on

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

name and value.

for example: Element.setAttribute(name, 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
  1. create the element using createElement();
  2. give it content using createTextNode();
  3. add it to the DOM using appendChild();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the textContent property of an element object for?

A

to give the newly created element content.

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

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

A

setAttribute(), .className, .classList

17
Q

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

A

code can be reused and in case we encountered an error, the stack trace will contain the name of the function, making it easier to find the origin of the error.