Javascript DOM onvolumechange Event on <audio> element

Introduction

Execute a JavaScript when the volume of an audio has been changed:

This example demonstrates how to assign an "onvolumechange" event to an audio element.

Try to change the volume in the bottom right corner.

View in separate window

<!DOCTYPE html>
<html>
<body>
<audio controls onvolumechange="myFunction()">
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>//ww w  . j a va 2s  . c o  m

<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The volume has been changed!";
}
</script>

</body>
</html>



PreviousNext

Related