Good day! Such is the problem: I want to implement switching songs of the html5 player by changing the src attribute using jQuery. The names of the songs have the form 1.mp3, 2.mp3 ... n.mp3

Here is the html code:

 <audio controls style="width:400px; float: right;"> <source class="mp" src="music/1.mp3" type='audio/ogg; codecs=vorbis'> </audio> 

Here is the jQuery code:

 $('.next').click(function() //next класс кнопки { $('.mp').attr('src','music/'+i+'.mp3'); //скорее всего ошибка здесь i++; //следующая песня, i - глобальная }); 

Nubian question to horror, but I do not know)

  • @denisKlimenko; And what doesn't work for you in this code? I did not experiment, but I have to plow everything. - Deonis
  • everything is already working)) - Bob Marley

1 answer 1

you can just write

 'music/' + i++ + '.mp3' 

but I would keep the list of songs in an array or hash

  • That is, the error was that I wrote together? : D As for the array, the idea is good, thanks) - Bob Marley