Javascript DOM HTML Audio loop Property get

Introduction

The loop property sets or gets if an audio will play again when finished.

This property mirrors the <audio> loop attribute.

When present, the audio will play again when it is finished.

Property Values

Value Description
true the audio should start playing again when it is finished
false Default. the audio should NOT start playing again when it is finished

Find out if the audio should play again every time it is finished or not:

var x = document.getElementById("myAudio").loop;

Click the button to find out if the audio should play again when finished or not.

View in separate window

<!DOCTYPE html> 
<html> 
<body> 

<audio id="myAudio" controls loop>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>/*from   w ww. j  ava  2 s . c o  m*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myAudio").loop;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body> 
</html>



PreviousNext

Related