0
Hello good night to all!
I created elements in my HTML (span) and now I need to add a click event to display a sound whenever I click on some span tag that was created by Document.createelement but when I try the sound is added only when I create the direct span tag by HTML.
As you can see in the print below with the exception of the first, all other squares are created by Javascript with createelement, I would like to click on each square and play a sound that will be played randomly on each square.
The problem is that when I put the remote:
let sound = document.querySelectorAll('span');
This is only taking the first span that was created directly by my HTML and not an arrayLike so I can add click event with a foreach. Can someone help me? I am creating this just for study purposes, I thank all of you already!
See if this helps you: https://answall.com/a/50265/74
– bfavaretto
Particularly the part about delegation of events
– bfavaretto
"Display a sound" is a beautiful of a synesthesia.
– Piovezan
@Piovezan, in the case did not say right but this "Display a sound" would take a part of the music I put in my HTML and activate with var.play() in the function.
– Filipe Gomes
@bfavaretto, I’ll give a read later, thanks for the indication!
– Filipe Gomes