questions5 Flashcards

1
Q

[Bubbling] How should we go if we want that any new additional element in the dom tree has a click handler?

A

We have two variants, add the EventListener directly on a newly created element or with event delegation.

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

event delegation

A

It`s a pattern when instead of assigning EventListeners on each element we are assigning it to the common ancestor element. In the handler, we are getting e.target to check where the event has actually happened and handle it.

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

[Capturing] In which order will these handlers be invoked? How could we change this order?
document.querySelector(‘body’).addEventListener(‘click’, callback1); document.querySelector(‘button’).addEventListener(‘click’, callback2);

A

Button first then Body. We need to give a 3rd parameter true to tern on the Capturing so the Body will be first and then the button

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

StopPropagation()

A

event.stopPropagation() stops the move upwards, but on the current element all other handlers will run.
To stop the bubbling and prevent handlers on the current element from running, there’s a method event.stopImmediatePropagation(). After it no other handlers execute.

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

PreventDefault()

A

gives you the ability to prevent a browser’s default behavior for events.
for example, when you click on a checkbox it’ll toggle the check. However, if you use preventDefault it will actually stop the browser from doing that.
You can use preventDefault on all sorts of different HTML elements.
There are some events that the browser can’t prevent from happening. For example, events like scroll and wheel (for mouse wheel events!)

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

Target and Current Target difference

A

event. target – the deepest element that originated the event.
event. currentTarget (=this) – the current element that handles the event (the one that has the handler on it)

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

bubbling

A

events “bubble” from the inner element up through parents

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

event.target

A

e.target is the actual element inside the form that was clicked.

this – is the “current” element, the one that has a currently running handler on it.

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