S
S
Sergey Burduzha2017-07-05 15:08:23
JavaScript
Sergey Burduzha, 2017-07-05 15:08:23

How to play an audio file on button click using the audio tag?

There is the following code:
start autoplay


$('.startMusic').on('click', function(){
$('.music').attr({
'autoplay': true,
'paused': false,
'controls' : true
});
});

When you click on the button, the music should play, but this does not happen, why?
What else have I not learned? It seems that I looked through all the properties of the audio object, but did not find the reason for launching the file.
Need help...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-07-05
@serii81

$('.startMusic').on('click', function(){
  $('.music')[0].play()
});

Here are a couple more examples for you .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question