-2
I’m creating a kind of playlist (so far everything on it works as expected) and I did a detail for the selection of songs where I created for each song a div with the name of the song, and instead of creating element by element for each song in the folder I made a loop to create separate Ivs and add in another:
var musicas = ['Aqui', 'vai', 'o', 'nome', 'das', 'músicas'];
var musics = document.querySelector('.musics');
i = 0;
while(i < musicas.length) {
var nome_musicas = document.createElement('div');
musics.appendChild(nome_musicas);
nome_musicas.classList.add('name');
nome_musicas.classList.add('music_number_' + i);
nome_musicas.innerHTML = musicas[i];
i++;
}
My problem now is to find a logic, when I click on the div with the song she give me the name of the song that is inside her so I can do another step to play the selected song.
Got it! It is that in the other functions of the playlist (pass the music, return of music, leave random and auto pass the music when one is over) I used a counter that picked the position of the music in the list and passed to tag audio play. My idea in this creation of Divs to be the list of songs was that when I clicked on a div she gave me the name of the song inside her and I check in which position of the 'songs' he is in the variable and pass this position to the counter for him to play the chosen song.
– Paulo Fellipe