+ 1

Why does the second script code break the first? (JavaScript)

https://code.sololearn.com/WUnudHPrv2Ke/#html I made these two codes as two examples to understand the difference between bubbling and capturing, they work fine by their own, but when they are added together like this for some reason they effect each other, but why? They have different id, so I don't understand what's the problem.

12th Oct 2020, 4:50 PM
Karak10
Karak10 - avatar
5 ответов
+ 1
Quick fix: Just rename the variable in second script
12th Oct 2020, 5:03 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 2
Karak10 Every small script gets squished into one long script. The variable and functions also carry over.
12th Oct 2020, 6:43 PM
BlazingMagpie
BlazingMagpie - avatar
+ 1
Karak10 I don't know exact mechanics at work, but I assume redeclaring function with same name simply reassigns a pointer to a new function. As you added a listener to the old function, it is still accessible through it, while function with that name now is different function.
12th Oct 2020, 7:13 PM
BlazingMagpie
BlazingMagpie - avatar
0
🇮🇳Vivek🇮🇳 it worked, I don't understand why tho, I thought it's okay to reuse same names for varieties as long as they are in different script tags
12th Oct 2020, 5:16 PM
Karak10
Karak10 - avatar
0
BlazingMagpie I used same function names tho and there is no problem, everything works fine
12th Oct 2020, 6:53 PM
Karak10
Karak10 - avatar