0

Event listener doesn't work [solved]

Event listeners doesn't work when there is any element after paragraph All in code I don't know why they don't work https://code.sololearn.com/WvxrA0GoY5Ty/?ref=app Upd: i replaced div.innerHTML+="<br>" by document.createElement("br") and it works. Idk why, but ok

18th Jul 2022, 1:24 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
16 Réponses
+ 3
I added some comments in the code https://code.sololearn.com/WE3z9L0YbEDL/?ref=app
18th Jul 2022, 3:17 PM
Lisa
Lisa - avatar
+ 1
What is the code supposed to do? What is "data"?
18th Jul 2022, 1:55 PM
Lisa
Lisa - avatar
+ 1
To highlight what I changed in your code. LOOK AT THE CODE
18th Jul 2022, 3:44 PM
Lisa
Lisa - avatar
+ 1
Click on paragraph 1, hi1 will be alerted, click paragraph 2, hi2 will be alerted That means your data functions are attached to the corresponding elements
18th Jul 2022, 3:54 PM
Lisa
Lisa - avatar
+ 1
You can add as many <br> as you want. The breaks are not critical to the functionality, that is why I removed them in the example. You need to adjust your code yourself.
18th Jul 2022, 4:00 PM
Lisa
Lisa - avatar
+ 1
In your code, only the click event for the last paragraph works. I demonstrated how to make the events work. You need to decide yourself how many line breaks you want and where to put them. I gave an example, not a solution to whatever task.
18th Jul 2022, 4:44 PM
Lisa
Lisa - avatar
0
Lisa this functions is functions which executed when paragraph is clicked. First function for first paragraph, second for secons etc.
18th Jul 2022, 2:02 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
Lisa okay But for what?
18th Jul 2022, 3:30 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
Lisa a you added and removed some comments, right?
18th Jul 2022, 3:47 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
You changed append to appendChild also, and little changed parametrs for function, but this changes nothinh
18th Jul 2022, 3:50 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
Lisa yes, it works, but I had shown it in my code (read comments). You just removed the extra <br> but i need to have this <br>.
18th Jul 2022, 3:55 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
I mean you did something, your code works but your code doesn't give information on actual solving
18th Jul 2022, 3:58 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
Lisa my tests shows that they are critical. Have br - no functionality. No be - have functionality. I don't know why, so i ask
18th Jul 2022, 4:03 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
My code have this string: div.innerHTML +="<br>". if i remove it, code will work. But I don't want to remove. So i wanted to make code works with br I think it is bug which not depends on us code
18th Jul 2022, 4:06 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
Did you read comments in code? You removed br because it wasn't bad for functionality? But i written that they it was
18th Jul 2022, 4:07 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
0
Okay i just don't understand for what did you do that Your code almost same as mine (except commensts)
18th Jul 2022, 4:58 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar