Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

HTML ondurationchange Attribute


Definition and Usage

The durationchange event occurs when the duration data of the specified audio/video is changed.

Note: When an audio/video is loaded, the duration will change from "NaN" to the actual duration of the audio/video.

During the loading process of an audio/video, the following events occur, in this order:

  1. loadstart
  2. durationchange
  3. loadedmetadata
  4. loadeddata
  5. progress
  6. canplay
  7. canplaythrough

Applies to

The ondurationchange attribute is part of the Event Attributes, and can be used on the following elements:

Elements Event
<audio> durationchange
<video> durationchange

Examples

Audio Example

Run "myFunction" when the audio is ready to start playing:

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

Video Example

Run "myFunction" when the video is ready to start playing:

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

Browser Support

The ondurationchange attribute has the following browser support for each element:

Element
audio Yes 9.0 Yes Yes Yes
video Yes 9.0 Yes Yes Yes