Audio controls Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The controls property sets or gets whether a audio should display standard audio controls.

Audio controls should include:

  • Play
  • Pause
  • Seeking
  • Volume

Set the controls property with the following Values

Value Description
true|false Sets whether a audio should have controls displayed
  • true - Indicates that controls are displayed
  • false - Default. Indicates that controls are NOT displayed

Return Value

A Boolean, returns true if audio controls are displayed, otherwise it returns false

The following code shows how to disable controls for an audio:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls>
  <source src="your.ogg" type="audio/ogg">
  <source src="your.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>/* w  w w.  j a va2  s. c  om*/


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

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

<script>
function myFunction() {
    document.getElementById("myAudio").controls = false;
}
</script>

</body>
</html>

Related Tutorials