Javascript DOM HTML Audio controls Property set

Introduction

Enable controls for an audio:

document.getElementById("myAudio").controls = true;

View in separate window

<!DOCTYPE html> 
<html> 
<body> 

<audio id="myAudio" controls>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio><br>
<p id="demo"></p>
<button onclick="enableControls()" type="button">Enable controls</button>
<button onclick="disableControls()" type="button">Disable controls</button>
<button onclick="checkControls()" type="button">Check controls status</button>

<script>
var x = document.getElementById("myAudio");
function enableControls() { //from w  ww.j  ava  2s  .  co  m
  x.controls = true;
  x.load();
} 

function disableControls() { 
  x.controls = false;
  x.load();
} 
 
function checkControls() { 
  document.getElementById("demo").innerHTML = x.controls;
} 
</script> 

</body> 
</html>

The controls property sets or gets if a <audio> should show standard audio controls.

This property mirrors the <audio> controls attribute.

When present, the audio controls will be displayed.

Possible value:

Value Meaning
true controls are displayed
false Default. controls are NOT displayed



PreviousNext

Related