Javascript DOM onvolumechange Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

object.addEventListener("volumechange",
       myScript);

This example uses the addEventListener() method to attach a "volumechange" event to a video element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Try to change the volume in the bottom right corner.</p>

<video controls id="myVideo">
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>/*from w w w. j  a v a2 s  .  c  o m*/

<p id="demo"></p>
<script>
document.getElementById("myVideo").addEventListener("volumechange", myFunction);

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

</body>
</html>
Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio> and <video>



PreviousNext

Related