1.4 - Events in Detail Flashcards

1
Q

Mouse events can be splitted into 2 categories, simple and complex, it is right?

A

YES

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

Mouse events can be split into how many categories? and who are them

A

2 categories

simple and complex

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

Describe some of the most used simple mouse envents

A

mousedown / mouseup

mouseover / mouseout

mousemove

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

Some of the most used mouse simple events are:

mousedown / mouseup

mouseover / mouseout

mousemove

A

YES

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

mousedown / mouseup

Describe it

In what category is it?

A

description: mouse button is clicked / released over an element
category: simple

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

mouseover / mouseout

Describe it

In what category is it?

A

description: mouse pointer comes over / out from an element
category: simple

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

mousemove

Describe it

In what category is it?

A

describe: every mouse move over an elemen triggers that event
category: simple

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

some of the most used complex mouse events are

click

contextmenu

dblclick

?

A

yes

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

some of the most used complex events are?

A

click

contextmenu

dblclick

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

complex events are made of simple ones?

A

yes

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

Complex events are made of …?

A

simple ones

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

click event

Describe it

In what category is it?

A

description: triggers after mousedown and then mouseup is released over the same element
category: complex

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

contextmenu event

Describe it

In what category is it?

A

description: triggers after mousedown if the right mouse button was used
category: complex

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

dblclick

Describe it

In what category is it?

A

description: triggers after a double click over an element.
category: complex

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

Can an action trigger multiple events?

explain it with an example

A

YES

a click first triggers mousedown, when the button is pressed, then mouseup and click when it’s released

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

How is the events order in the case when a single action initiates multiple events?

describe the click event

A

Their order is fixed.

The handlers are called in the order

mousedown -> mouseup -> click

A click first triggers mousedown, when the buttos is pressed, then mouseup and click when it’s released

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

The which property is:

allows to get the mouse button ?

A

YES

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

What is the usage or purpose of the which property on click-related events?

A

Click related events always have the which property that allows to get the button

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

The which property it’s used for click and contextmenu events?

A

No, because those happens only on left click and on right click only

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

When it is usefull the which property on click related events?

A

When we are tracking mousedown and mouseup, because these events trigger on any button, so which allows to distinguish between “right-mousedown” and “left-mousedown”

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

Name the possible values of the which property

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

All mouse events include the information about pressed modifier keys?

A

YES

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

Can we know about any modifier key being pressed, when using mouse events?

and why?

A

YES

because all mouse events include the information about pressed modifier keys

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

What are the modifiers keys?

A

shiftKey

altKey

ctrlKey

metaKey (cmd for mac)

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

All mouse events have coordinates in 2 flavours

who are them?

A

window-relative: clientX and clientY

document-relative: pageX and pageY

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

When clicking on text what side-effect may be disturbing?

A

That a double click selects the text

If we want to handle click events ourselves, then the “extra” selection doesn´t look good.

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

Why mouseove/mouseout and mouseenter/mouseleave are special, what do they have?

A

the have a relatedTarget

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

In mouseover

what it means

event.target

event.relatedTarget

A

event.target - is the element where the mouse came over

event.relatedTarget - is the element from which the mouse came

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

In mouseout

what it this:

event.target

event.relatedTarget

?

A

event.target - is the element that mouse left

event.relatedTarget - is the new under-the-pointer element (that mouse left for)

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

relatedTarget can have a value of null?

A

YES

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

When and what it means that, relatedTarget can have a value of null?

A

It’s normal and just means that the mouse came not from another element, but from out of the window. Or that it left the window.

Keep that possibility in mind wen using event.relatedTarget. If we access event.relatedTarget.tagName, then there will be an error.

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

How can we explain this situation?

A

According to the browser logic, when using mouseover/mouseout the mouse cursor may be only over a single element at any time - the most nested one (and top by z-index).

So if it goes to another element (even a descendant) then it leaves the previous one. That simple!

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

What are the differences between

mouseenter/mouseleave and mouseover/mouseout

?

A

1 - Transitions inside the element are not counted.

2 - Events mouseenter / mouseleave do not bubble

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

What could be a problem when using mouseenter/mouseleave?

A

That they don´t bubble.

So we can´t use the event delegation pattern on them.

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

Who are the events that trigger even when we go from the parent element to a child element? and why?

A

mouseover / mouseout

They assume that the mouse can be only over one element at one time - the deepest one.

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

Who are the events that don´t bubble?

A

mouseenter / mouseleave do not bubble

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

Who are the events that only track whether the mouse comes inside and outside the element as a whole?

A

mouseenter / mouseleave

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

Who are the events that do not trigger when the mouse goes to a child element?

A

mouseenter / mouseleave

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

Who are the events that have an additional target: relatedTarget ?

A

mouseover / mouseout

mouseenter / mouseleave

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

Who are the events that assume that the omuse can be only over one element at one time - the deepest one?

A

mouseover / mouseout

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

What is the difference between mousemove, mouseenter and mouseover

A

The mouseover event triggers when the mouse pointer enters the div element, and its child elements.

The mouseenter event is only triggered when the mouse pointer enters the div element.

The mousemove event triggers every time the mouse pointer is moved over the div element.

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

When listening for the event mousemove, it means that:

every pixel leads to an event?

Explain the answer with an example

A

NO

The browser checks the mouse position from time to time. And if he notices changes then triggers the events.

That means that if the visitor is moving the mouse very fast then DOM-elements may be skipped:

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

it is true that

clientX/Y coordinates are relative to the top left corner of the visible part of the page(the viewport), “seen” through browser window

A

yes

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

It is true that

pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),

A

yes

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

Tanto pageX/Y como clientX/Y

Son´numeros?

A

Si son números, que representan coordenadas

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

Tanto pageX/Y como clientX/Y sabemos que son números, pero que representan esos números?

A

Son coordenadas

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

Tanto pageX/Y como clientX/Y son números, que representan coordenadas, en relación a qué?

A

pageX/Y: sus coordenadas son en relación a la esquina superior izquierda de toda la página renderizada(inclusive las partes ocultas por hacer scroll)

clientX/Y: sus coordenadas son en relación a la esquina superior izquierda en relación a la viewport( la parte actualmente visible en el navegador )

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

complete:

……. …. coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),

A

pagex / y

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

Complete:

………. …. coordinates are relative to the top left corner of the visible part of the page(the viewport), “seen” through browser window

A

clientX / Y

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

What is the viewport in HTML

A

Is the part of the webpage that the user can currently see. The scrollbars move the viewport to show other parts of the page

Y para evitar cualquier confusión, no es ni el tamaño de la ventana(window) del navegador, ni la resolución de pantalla. Dos ventanas con el mismo tamaño, pero un navegador con más barras de herramientas mostradas tendrá una ventana de visualización más pequeña

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

What is the difference between, clientX/Y and pageX/Y?

A

pageX, pageY, screenX, screenY, clientX and clientY returns a number which indicates the number of physical “css pixels” a point is from the reference point

The event point is where the user clicked, the reference point is a point in the upper left

pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling)

clientX/Y coordinates are relative to the top left corner of the visible part of the page(the viewport), “seen” through browser window

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

Describe pagex/pageY

A

pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),

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

Describe clientx/y

A

clientX/Y coordinates are relative to the top left corner of the visible part of the page, “seen” through browser window

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

Describe the image

A

pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),

while clientX/Y coordinates are relative to the top left corner of the visible part of the page(the viewport), “seen” through browser window.

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

pageX, pageY, screenX, screenY, clientX, clientY

it is true that returns a number wich indicates the number of physical “css pixels” a point is from the reference point?

A

yes

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

pageX, pageY, screenX, screenY, clientX, clientY

it is true that returns a number wich indicates?

A

the number of physical “css pixels” a point is from the reference point?

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

If we want to track any input into an < input > field, keyboard events are enough?

A

NO, they are not enough

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

When keydown and keyup events happens?

A

keydown happens when a key is pressed down

keyup happens when a key is pressed up

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

It is true to say that:

the event.key property allows to get the character

and

the event.code property get the “physical key code”

A

YES

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

How can we get a character

A

with event.key

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

How can we get the code of a character?

like “KeyX”

A

with event.code

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

Suppose a user works with different language, then switching language would make a totally different character if he press Z character.

How will change, key or code

A

event.code will be always the same “KeyZ”

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

Every key has the …. that depends on its location on the keyboard?

Complete the word

A

every has the code…

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

Name the key codes for

Letters

Digits

A

key: KeyA, KeyB, etc…

Digit: Digit0, Digit1, etc…

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

Name the key codes for special keys like:

Enter or backspace or the tab

A

Enter

Backspace

Tab

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

When working with event.code, case matters?

A

YES

The first letter of “Key” must be upppercase

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

Witch one is responsible for telling us exactly which key was pressed?

A

event.code tells us exactly which one was presed, and event.key is responsible for the “meaning” of the key: what is a “shift”

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

When a key is being pressed for a long enough time, it starts to ?

A

repeat, keydown triggers again and again

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

For all repeating keys the event object has what with what value?

A

the event object has the event.return property set to true.

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

Which key never generates a keyboard event

A

The Fn key, there is no keyboard event for it

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

It is true that the lifecycle of an HTML page has three important events?

A

YES

They are:

DOMContentLoaded

load

beforeunload/unload

72
Q

The lifecycle of an HTML page has how many important events?

and who are them?

A

3

DOMContentLoaded

load

beforeunload/unload

73
Q

The lifecycle of an HTML page has 3 important events.

One of them is:

beforeunload/unload

and it does: when the user is leaving the page?

A

YES

74
Q

The lifecycle of an HTML page has 3 important events.

One of them is:

DOMContentLoaded

and what it does is: The browser fully loaded and parsed the HTML document, and the DOM tree is built, but external resources like pictures, stylesheets and subframes may be not yet loaded.

A

YES

75
Q

The lifecycle of an HTML page has 3 important events.

One of them is:

load

and what it does: The browser loaded all resources (images, styles, etc).

It´s run when not just the HTML has been parsed, but all of the resources like images have been loaded

This is the time the page is fully rendered, meaning if you add something to the page now, there will be a noticable “flash” of the page before your new element appears?

A

YES

76
Q

The lifecycle of an HTML page has 3 important events.

One of them is:

DOMContentLoaded

What it does?

A

The browser fully loaded and parsed the HTML document, and the DOM tree is built, but external resources like pictures and stysheets may be not yet loaded.

Another way to express it is: It occurs when all of the HTML is ready to interact with, but often before its been rendered to the screen.

77
Q

The lifecycle of an HTML page has 3 important events.

One of them is:

load

What it does?

A

The browser loaded all resources (images, styles, etc)

Sometimes we want to run our code when not just the HTML has been parsed, but all of the resources like images have been loaded.

This is the time the page fully rendered, meaning if you do add something to the page now, there will be a noticable “flash” of the page before your new element appears.

78
Q

The lifecycle of an HTML page has 3 important events.

One of them is:

beforeunload/unload

What it does?

A

when the user is leaving the page

79
Q

It is true that the event DOMContentLoaded happens on the document object, and it`s useful for: When the DOM is ready, the handler can lookup for DOM nodes and initialize the interface?

It’s when the HTML document have been parsed, but the resorces not!

A

YES

80
Q

It is true that the load event it could be useful for: when additional resources are loaded, we can get image sizes (if not specified in HTML/CSS) etc.

The load event it´s run when not just the HTML has been parsed, but all of the resources like images have been loaded?

A

YES

81
Q

The beforeunload/unload event could be useful for when: the user is leaving: we can check if the user saved the changes and ask him whether he really wants to leave?

A

YES

82
Q

It is true that the DOMContentLoaded event could be useful for when…?

and it runs where?

A

DOMContentLoaded: DOM is ready, so the handler can lookup DOM Nodes, initialize the interface.

It’s when the HTML document is fully parsed, but not the resources like images, and stylesheets.

It runs on the document object, and we need to handler it with addEventListener

83
Q

The load event, could be useful for when?

A

load event: additional resources are loaded, we can get image sizes (if not specified in HTML/CSS) etc.

Sometimes we want to run our code when not just when the HTML document have been parsed, but all of the resources like images have been loaded.

This is the time the page is fully rendered, meaning if you do add something to the page now, there will be a noticable “flash” of the page before your new element appears.

84
Q

It´s true that the beforeunload/unload could be useful for when?

A

beforeunload/unload event: the user is leaving: we can check if the user saved the changes and ask him whether he really wants to leave.

85
Q

The DOMContentLoaded event happens where? on what object?

and we need to handler it with what?

A

On the document object

We need to handle it with the addEventListener method on the document object

86
Q

To cath the DOMContentLoaded event, we need to listenting how?

with gloval events, inline, or addEventListener?

A

We need to use addEventListener

document.addEventListener(“DOMContentLoaded”, ready);

87
Q

What is going to happen in this script

A

The DOMContentLoaded handler runs when the document is loaded(the HTML document is pared, but not the resources have been loaded), it not waits for the page load(the load event). So alert shows zero sizes

88
Q

When the browser initially loads HTML and comes across a < script >… < / script > tag, it can´t continue building the DOM. It must execute the script right now.

So what is going to happend if we are listening for DOMContentLoaded?

A

DOMContentLoaded may only happen after all such scripts are executed.

89
Q

We know that “script /script” tags pause the browser to continue building the DOM until it finish the execution of the script. What other “thing” can put the DOM building to pause?

A

External scripts (with src) also put DOM building to pause while the script is loading and executing. So DOMContentLoaded waits for external scripts as well.

90
Q

The DOMContentLoaded event can be “paused”, or will be executed in what cases?

A

DOMContentLoaded waits for script tags in the HTML document, and for external scripts (with src) to execute.

91
Q

When the browser is going to continue processing without waiting for scripts?

and what is the good thing, if there is one?

A

The only exception are external scripts with “async” and “defer” attributes.

The good thing is that the user can see the page before scripts finish loading.

92
Q

Attributes “async” and “defer” work only for …. ….?

A

external scripts

they are ignored if there’s no src

93
Q

Talking about order in “async” and “defer

how script with async executes?

A

Executes in the load-first order. Their document order doesn´t matter - which loads first runs first

94
Q

Talking about order in “async” and “defer

how script with defer executes?

A

Scripts with defer always execute in the document order (as they go in the document)

95
Q

Talking about external scripts with async and defer, in relation to order execution what are the differences?

A

Scripts with async execute in the load-first order. Their document order doesn´t matter - which loads first runs first.

Scripts with defer always execute in the document order ( as they go in the document )

96
Q

Talking about external scripts with async and defer, in relation to the event DOMContentLoaded, what are the differences

A

async: May load and execute while the document has not yet been fully downloaded. That happens if scripts are small or cached, and the document is long enough

defer: Execute after the document is loaded and parsed (they wait if needed) right before DOMContentLoaded.

(Se ejecuta despues de que el document se carga y analiza, justo antes de que DOMContentLoaded se ejecute)

97
Q

DomContentLoaded wait for external style sheets?

A

NO, external style sheets don´t affect DOM.

98
Q

When DOMContentLoaded needs to wait for stylesheets?

A

If we have a script after the style, then that script must wait for the stylesheet to execute

The script may want to get coordinates and other style-deendent properties of elements. Naturally, it has to wait for styles to load.

As DOMContentLoaded waits for scripts, it now waits for styles before them as well.

99
Q

It is true that Firefox, Chrome and Opera autofill forms on DOMContentLoaded?

A

YES

100
Q

If DOMContentLoaded is postponed by long-loading scripts, what could happen with autofill?

A

autofill also waits.

101
Q

Name one of minor benefts in using async and defer for external scripts?

A

They don´t block DOMContentLoaded and don´t delay browser autofill.

102
Q

The onload event where it happens, in what object?

A

In the window object

103
Q

The load event, where it happen, in what object?

and when it triggers?

A

The load event happen on the window object and triggers when the whole page is loaded including styles, images and other resources.

The example below correctly shows image sizes, because window.onload waits for all images

104
Q

How can we do something when a visitor leaves the page?

A

With the window.onunload event, we can do something there that doesn´t involve a delay, like closing related poups windows. But we can´t cancel the transtition to another page.

105
Q

What happens when a visitor initiated leaving the page or tries to close the window?

A

The window.onbeforeunload handler can trigger, for example asking for additional confirmation. It needs to return the string with a question.

window.onbeforeunload = function() {

return “There are unsaved changes. leave now?;

};

106
Q

When triggering the handler window.onbeforeunload, what some browsers will do?

A

Some browsers ignore the text and show their own message instead. It’s for sheer safety(pura seguridad), to protect the user from potentially misleading and hackish messages.

107
Q

What happens if we set the DOMContentLoaded handler after the document is loaded?

and why?

A

Naturally, it never runs!

108
Q

Let´s imagine that an external script with async attribute loads and runs asynchronously. Depending on the network, it may load and execute before the document is complete or after that, we can´t be sureSo what can we do in that case?

A

We should be able to know the current state of the document, and we can do it with the document.readyState property, that gives us information about it.

109
Q

It is true that the document.readyState property gives us information about the current state of the document?

A

YES

110
Q

How many possible values have the property document.readyState?

A

3 possible values

111
Q

So the document.readyState property gives us 3 possible values to know the current state of the document.

Name them?

A

loading

interactive

complete

112
Q

How many values gives us the property document.readyState, and

what are their name/s?

And what is the purpose of this property?

A

It has 3 possible values

loading, interactive, complete

It purpose it’s to give us information about the current state of the document.

113
Q

What it means the “loading” state of the document.readyState property?

A

The document is loading

114
Q

What it means the “interactive” state of the document.readyState property?

A

interactive: the document was fully read

115
Q

What it means the “complete” state of the document.readyState property?

A

complete: The document was fully read and all resources (like images) are loaded too.

116
Q

We know that we can check the current state of the document,

how can we do it?

Can we set up a handler or execute a code immediately if it’s ready?

A

we can do it via the property: document.readyState

We can check the document.readyState and setup a handler or execute the code immediately if it´s ready

117
Q

What event is the one that triggers when the state of the document change?

A

the readystatechange event

118
Q

Cuando una página se encuentra desde la fase inicial de carga(load) hasta que es cargada por completa, pasa por una serie de etapas. Hay algunos factores que pueden determinar cuando se van a ejecutar y cargar ciertas partes del document, por lo tanto, nombra algunos de estos factores que influyen o pueden hacer uso de las distintas fases…

A

The DOMContentLoaded event

the load event

the async attribute for script elements

the defer attribute for script elements

the location your scripts live in the DOM

119
Q

How many stages of a page load exists?

A

3 stages

120
Q

Describe the Stage 1 of a page load?

A

The first stage is when your browser is about to start loading a new page.

At this stage there isn´t anything interesting going on, a request has been made to load a page, but nothing has been downloaded yet.

121
Q

Describe the Stage 2 of a page load?

A

The raw markup and DOM of your page has been loaded and parsed:

The thing to note about this stage is that external resources like images and stylesheets have not been parsed. You only see the raw content specified by your page/document´s markup

122
Q

Describe the stage 3 of a page load?

A

The final stage is where your page is fully loaded with any images, stylesheets, scripts and other external resources making their way into what you see

This is the stage where your browser´s loading indicators stop animating, and this is also the stage you almost always find yourself in when interacting with your HTML document

123
Q

We know that there are 2 events that represents 2 important milestones while your page loads.

Who are them, and what stages they represent

A

DOMContentLoaded event fires at the end of Stage #2 when your page´s DOM is fully parsed.

load event fires at the end of Stage #3 once your page has fully loaded.

124
Q

Why load and DOMContentLoaded events are important?

A

Any code that works with the DOM(querySelector… etc), need to be sure that runs only after the DOM is fully loaded.

Accesing the DOM before it has fully loaded, may get incomplete results or no results at all.

125
Q

How can we be sure that our code runs before the DOM is ready?

A

Listening for the DOMContentLoaded event and let all of the code that relies on the DOM to run only after that event is overheard.

126
Q

It is true that script elements position in the DOM affects when they run?

and why?

A

The browser parses your DOM sequentially from the top to the bottom. Any script elements that get found along the way will get parsed in the order they appear in the DOM

127
Q

Because the DOM gets parsed from top to bottom, the scripts elements has access to all of the DOM elements that were already parsed.

What happens to the DOM elements that have NOT yet been parsed?

A

The script/s will not have access to any DOM elements that have not yet been parsed

128
Q

How can we avoid the whole process of listening to DOMContentLoaded event?

A

If we put all the code that deals with elements on the DOM at the bottom of the the page, the end behaivor is identical to what we are going to get listening to DOMContentLoaded event.

If we want to have our scripts at the top of the DOM, we need to listen to DOMContentLoaded event.

129
Q

It is say that the async attribute may a script to run:

The script will run whenever it is able to

It won´t block the rest of the browser from doing its thing

It will not run in order

A

YES

130
Q

async and defer, who is the one that will run in order?

A

async NOT run in order

defer YES it will run in order

131
Q

If we have several scripts markes as async how they will run?

A

They will NOT run in order.

They will run in a order DIFFERENT than what they were specified in your markup

132
Q

Scripts marked with defer run in thr order which they were defined?

A

YES

133
Q

Scripts marked with defer attribute when do they get executed, before or after DOMContentLoaded event gets fired?

A

before the DOMContentLoaded event gets fired

134
Q

Take a second and tell the order in which these scripts will run?

A

inline 1

external 1

inline 2

inline 3

external 3

external 2

The external 3, and external 2 scripts are marked as defer, and that´s why they appear at the very end, despite being declared in different locations in your markup.

135
Q

When is the right time to load your JS? regarding to the load and DOMContentLoaded event

1) Where to place the scripts?

2 Unless we are not creating a library that other will use, what can we do?

3) The script references, how can we marked them
4) If we have code that doesn´t rely on the DOM being loaded and runs as part of teeing things off for other scripts in your document, where we can place the scripts?

A

1) place the script references below the DOM directly above the closing body element
2) we don´t need to complicate the code by listening to the DOMContentLoaded or load event.
3) Mark the script references with asyn attribute.
4) we can place the script at the top of our page with the async attribute set on it.

136
Q

Document forms are members of the special collection: document.forms?

and

We can use both the name and the humber to get the form?

A

YES

YES

137
Q

1) Document forms are members of what special collection?
2) how can we get the form?

A

1) document.forms
2) We can use the name and the number to get the form

138
Q

When we have the form, any element is available in the named collection: form.elements?

A

YES

139
Q

When we have a form, hown can we get the elements?

A

Any element is available in the named collection: form.elements.

140
Q

What happens to form.elements if there are multiple elements with the same name ex: radio buttons

A

form.elements[name] is a collection

141
Q

When working with forms, the navigation properties as document.form, form.elements, etc… depende on the tag structure? and why?

A

NO, all elements, no matter how deep they are in the form, are available in form.elements.

142
Q

on a form, fieldsets support the elements property?

A

YES

143
Q

When working with forms, what is the shorter notation for accessing elements, insetad of form.elements.login

A

The shorter notation is form[index/name]

form.login

144
Q

It is true that for any element, the form is avaiable as element.form. So a form references all elements, and elements, reference the form.

A

YES

145
Q

Exist a backreference when working with elements on a form, between a form and their elements? explain it?

A

YES

For any element, the form is avaiable as element.form. So a form references all elements, and elements reference the form.

146
Q

How can we access the value of an input or for example a checkbox?

A

We can access the values as

input.value

input.checked

147
Q

It is true that an element receives a focus when the user either clicks on it or uses the Tab key on the keyboard?

A

YES

148
Q

It is true that the HTML attribute autofocus puts the focus into an element by default when a page loads.

A

YES

149
Q

What are the possibles ways that elements can receive focus

A

1 - when the user either clicks on it or uses the Tab key.

2 - With the HTML attribute autofocus, it puts the focus into an element by default when a page loads.

150
Q

What it means Focusing?

A

It means: “prepare to accept the data here”

151
Q

loosing focus (“blur”) when it could happend?

A

When a user clicks somewhere else or presses Tab to go to the next form field, or there are other means as well.

152
Q

loosing the focus generally means? and what could we do when loosing focus

A

“The data has been entered”

we can run the code to check it or even to save it to the server and so on.

153
Q

What is the purpose of using JS when focus/blur if moderl HTML allows validations using input attributes like: required, pattern, etc

A

JS can be used when we want more flexibility, we could automatically send the changed value to the server if it’s correct.

154
Q

What it does the methods:

elem.focus()

elem.blur()

A

.focus() - it sets the focus on the element

.blur() - unset the focus on the element

155
Q

What this code will do?

A

The visitor is unable to leave the input if the value is invalid.

If we enter something into the input and then try to use Tab or click away from the input, then onblur returns the focus back.

156
Q

Javascript can cause “focus loss” ?

explain it

A

YES it can cause it

1 - An alert moves focus to itself, it causes the focus loss at the element (blur event), whenthe alert is dismissed, the focus comes back (focus envet)

2 - In af element is removed from DOM, then it also causes the focus loss. If it is reinserted later, then the focus doesn´t return.

157
Q

Hown can an alert box cause a focus loss?

A

An alert moves the focus to itself, so it causes the focus loss at the element(blur event), and when the alert is dismissed, the focus comes back (focus event)

158
Q

If an element is removed from the DOM, it causes focus loss? explain it?

A

YES

If an element is removed from the DOM, then it also causes the focus loss. If it is reinserted later, then the focus doesn´t return.

159
Q

When working with focus events, we know that JS by itself sometimes can cause a focus-loss(on alert and when an element is removed from the DOM), so what could we do to prevent or take care of this scenarios, if we want to track user-initiated focus-loss?

A

We can be careful when using these events. If we want to track user-initiated focus-loss, then we should evade causing it by ourselves.

160
Q

All elements support focusing? explain it

A

NO

elements that exist to format something like div, span, table, are unfocusable by default

161
Q

focus/blur support is guaranteed for elements that … ?

A

elements that visitors can interact with: button, input, select, a, etc…

162
Q

We know that some elements(the one that exist to format something: div, span…) are unfocusable by default, how can we make them/transform them to focusables

A

using the HTML attribute tabindex

163
Q

What is the purpose of the HTML attribute

tabindex

A

To specify the order number of the element when Tab is used to switch between them.

164
Q

the HTML attribute tabindex has how many special values, and what they do?

A

2 special values

tabindex=”0” - makes the element the last one

tabindex=”1” - means that Tab should ignore that element.

165
Q

Any element that has the tabindex html attribute can be focused?

A

YES

166
Q

What is the order of focusing on pressing tab

A

The order is like this:

1, 2, 0 (zero is always the last). Normally li does not support focusing, but tabindex full enables it

167
Q

Can we add the tabindex html attribute, via JS?

if yes, how?

A

YES

We can add tabindex from JS by using the elem.tabIndex property.

168
Q

focus and blur, make use of the capturing of bubbling phase

A

capturing phase

169
Q

What is going to happend on this code:

A

It doesn´t work, because when user focuses on an input, the focus event triggers on that input only. It doesn´t bubble up. So form.onfocus never triggers

170
Q

What will happend on this code, this will work?

A

Yes it work, because focus/blur do not bubble up, but propagate down on the capturing phase.

171
Q

Since focus/blur do not bubble, what other similar events do we have that bubble up?

A

focusin and focusout

They must be assigned with the method addEventListener, not on on<event></event>

172
Q

This will work?

A

Yes it will propage thanks to the bubbling phase that focusin and focusout event make use of.

And we are correcly adding these two events with addEventListener

173
Q

It is true that the change event triggers when the element has finished changing?

A

YES

174
Q

When the change event is going to trigger?

example for:

inputs, select, input type=checkbox/radio

A

The event occurs

inputs: means that the event occurs when it looses focus

select, input type=checkbox/radio - triggers right after the selection changes

175
Q

It is true that the input event triggers every time a value is modified?

A

YES

176
Q

When the input event triggers?

A

every time a value is modified

177
Q

When we have an input form element, and we want to handle every modification of it, what event is the best choice?

give one reason

A

the input event

It works on any value change, even those that doesn´t involve keyboard actions.