Latest web development tutorials
 

onvolumechange Event

< Event Object

Example

Execute a JavaScript when the volume of a video has been changed:

<video onvolumechange="myFunction()">
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The onvolumechange event occurs each time the volume of a video/audio has been changed.

This event is invoked by:

  • Increasing or decreasing the volume
  • Muting or unmuting the media player

Tip: Use the volume property of the Audio/Video Object to set or return the audio volume of an audio/video.


Browser Support

The numbers in the table specify the first browser version that fully supports the event.

Event
onvolumechange Yes 9.0 Yes Yes Yes

Syntax

In HTML:

<element onvolumechange="myScript">
Try it Yourself »

In JavaScript:

object.onvolumechange=function(){myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("volumechange", myScript);
Try it Yourself »

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.


Technical Details

Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio> and <video>
DOM Version: Level 3 Events

Examples

More Examples

Example

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

<audio onvolumechange="myFunction()">
Try it Yourself »

Example

Using the volume property to set the volume:

document.getElementById("myVideo").volume = 0.2;
Try it Yourself »

< Event Object