Javascript examples for DOM HTML Element:Audio
The loop property sets or gets whether an audio should play again and again.
This property reflects the <audio> loop attribute.
Set the loop property with the following Values
Value | Description |
---|---|
true|false | Sets whether the audio should start playing over again, every time it is finished |
A Boolean, returns true if the audio starts playing over again, every time it is finished. Otherwise it returns false
The following code shows how to Set the audio to loop:
<!DOCTYPE html> <html> <body> <audio id="myAudio" controls loop> <source src="your.ogg" type="audio/ogg"> <source src="your.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio>//from w w w . j ava 2 s. c om <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myAudio").loop = true; } </script> </body> </html>