Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html> 
<html> 
<body> 
<h1>HTML DOM Events</h1>
<h2>The onvolumechange Event</h2>
<video id="myVideo" width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>
<p>Try to change the volume.</p>
<button onclick="setHalfVolume()" type="button">Set volume to 0.2</button>
<button onclick="setFullVolume()" type="button">Set volume to 1.0</button>
<p id="demo"></p>
<script>
// Get the video element:
const video = document.getElementById("myVideo");
// Attach a "volumechange" event to the video:
video.addEventListener("volumechange", getVolume);
// Display the current audio volume:
function getVolume() { 
  document.getElementById("demo").innerHTML = "The audio volume is: " + video.volume;
} 
// Set the audio volume to 0.2
function setHalfVolume() { 
  video.volume = 0.2;
} 
// Set the audio volume to 1.0 (the highest)
function setFullVolume() { 
  video.volume = 1.0;
} 
</script> 
</body> 
</html>