I want to change audio src when I click on each a tags, for example when I click on the first a tag, just the first src in the array should play and so on. I wrote this code but by clicking on a tags the src will change every time (I want the first src just for the first a tag and second for second...);
$(function () {
const sources = [
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10'
];
for (var i = 0; i < $('a').length; i++) {
$('a').eq(i).on('click', function () {
if (i <
sources.length ) {
i++;
} else {
i = 0;
}
$('#music').attr('src', sources[i]);
$('#music').get(0).play();
})
};
});