HTML Audio/Video DOM volumechange Event
HTML Audio/Video DOM Reference
Example
Display a message when the video's volume changes:
var vid = document.getElementById("myVideo");
vid.onvolumechange = function() {
alert("Volume changed");
};
Try it »
The bottom of this article contains more examples.
Definition and Usage
The volumechange event is triggered when the volume of the audio/video changes.
This event is triggered in the following situations:
- Increasing or decreasing the volume
- Muting or unmuting
Tip: Use the Audio/Video object's volume property to set or return the volume of the audio/video.
Browser support
The numbers in the table indicate the version number of the first browser to support the event.
| Events | |||||
|---|---|---|---|---|---|
| volumechange | Yes | 9.0 | Yes | Yes | Yes |
Syntax
In HTML:
<
audio|video
onvolumechange="
myScript
">Try it
In JavaScript:
audio|video
.onvolumechange=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
audio|video
.addEventListener("volumechange",
myScript
);
Try it
Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.
Technical Details
| Supported HTML tags: | |
|---|---|
| Supported JavaScript objects: | Audio, Video |
More examples
Example
Display a message when the audio's volume changes:
var aud = document.getElementById("myAudio");
aud.onvolumechange = function() {
alert("Volume changed!");
};
Try it »
HTML Audio/Video DOM Reference