onvolumechange event

Definition and usage

The onvolumechange event occurs each time the volume of video/audio is changed.

This event is triggered by the following situations:

  • Increase or decrease the volume
  • Mute or unmute the media player

Tip:Please use the audio/video object's volume property to set or return the volume of audio/video.

Example

Example 1

Execute JavaScript when the video volume changes:

<video onvolumechange="myFunction()">

Try it yourself

Example 2

Execute JavaScript when the audio volume changes:

<audio onvolumechange="myFunction()">

Try it yourself

Example 3

Use the volume property to set the volume:

document.getElementById("myVideo").volume = 0.2;

Try it yourself

Syntax

In HTML:

<element onvolumechange="myScript">

Try it yourself

In JavaScript:

object.onvolumechange = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("volumechange", myScript);

Try it yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.

Technical details

Bubbling: Not supported
Cancelable: Not supported
Event type: Event
Supported HTML tags: <audio> and <video>
DOM version: Level 3 Events

Browser support

Tallene i tabellen angiver den første browserversion, der fuldt ud understøtter dette event.

Events Chrome IE Firefox Safari Opera
onvolumechange Support 9.0 Support Support Support