All language subtitles for 190 Event Propagation_ Bubbling and Capturing.en_US1

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

JavaScript events have a very important property.

They have a so-called capturing phase and a bubbling phase.

So what does that mean?

Well, let's find out.

So here we have a very simple HTML document

along with a dumb tree,

but only for the anchor element

that's represented in red here.

So here we can see exactly all the parent elements

of that red anchor element.

And that's because we're gonna simulate what exactly happens

with an event when someone clicks on that link.

So maybe pause the video for a minute,

and analyze this structure here.

But anyway, let's now say that a click happens on the link.

And as we already know,

the dumb then generates a click event right away.

However, this event is actually not generated

at the target element.

So at the element, where the event happened,

in this case, the click on the anchor element.

Instead, the event is actually generated

at the root of the document,

so at the very top of the dumb tree.

And from there, the so-called capturing phase happens,

where the event then travels all the way down

from the document route to the target element.

And as the event travels down the tree,

it will pass through every single parent element

of the target element.

So in our example, here, the HTML element,

the body element, the section, then the paragraph,

until it finally reaches its target.

As soon as the event reaches the target,

the target phase begins,

where events can be handled right at the target.

And as we already know,

we do that with event listeners, such as this one.

So event listeners wait for a certain event

to happen on a certain element,

and as soon as the event occurs,

it runs the attached callback function.

In this example,

it will simply create this alert window, all right?

And again, this happens in the target phase.

All right, now, after reaching the target,

the event then actually travels

all the way up to the document route again,

in the so-called bubbling phase.

So we say that events bubble up

from the target to the document route.

And just like in the capturing phase,

the event passes through all its parent elements,

and really just the parents,

so not through any sibling elements.

So as an event travels down and up the tree,

they pass through all the parent elements,

but not through any sibling element.

But now you might be wondering why is this so important?

Why are we learning about all this detail?

Well, it is indeed very important because basically,

it's as if the event also happened

in each of the parent elements.

So again, as the event bubbles through a parent element,

it's as if the event had happened

right in that very element.

What this means is that if we attach

the same event listener, also for example,

to the section element, then we would get

the exact same alert window for the section element as well.

So we would have handled the exact same event twice,

once at its target, and once at one of its parent elements.

And this behavior will allow us

to implement really powerful patterns,

as we will see throughout the rest of the section.

So this really is very, very important to understand.

Now by default, events can only be handled in the target,

and in the bubbling phase.

However, we can set up event listeners in a way

that they listen to events in the capturing phase instead.

Also, actually not all types of events

that do have a capturing and bubbling phase.

Some of them are created right on the target element,

and so we can only handle them there.

But really, most of the events do capture and bubble

such as I described it here in this lecture.

We can also say that events propagate,

which is really what capturing and bubbling is.

It's events propagating from one place to another.

All right, so I hope that all of this made sense,

and so let's now actually see this in action

in the next video.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.