how to make a music playlist html

Solutions on MaxInterview for how to make a music playlist html by the best coders in the world

showing results for - "how to make a music playlist html"
Davide
20 Nov 2019
1<!-- There are several ways but if you are a begginer this is quite simpler-->
2
3<!--In Your JavaScript Code-->
4<script>
5  <!-- Make an array of the song locations in javascript -->
6  Arr = ['song1.mp3', 'song2.mp3', 'song3.mp3']
7
8  <!-- Make the function -->
9  function func(x) {
10    document.getElementById('musicPlayer').setAttribute('src', Arr[x])
11  }
12</script>
13
14<!-- In Your Html Code -->
15<!-- Create a music element -->
16<audio controls id="musicPlayer" autoplay>
17<source src="" type="audio/mp3"> <!--Make sure not to put anything in the scr-->
18</audio>
19
20<!-- Create a few buttons -->
21<button onclick="func(0)">Song 1</button>
22<button onclick="func(1)">Song 2</button>
23<button onclick="func(2)">Song 3</button>
24
25<!-- I hope this was helpful! -->