Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML ondurationchange Attribute

  • Last Updated : 18 Aug, 2020

The HTML ondurationchange Attribute is an event attribute that occurs when the audio/video duration is changed. The duration of the audio/video is changed from “NaN” to the actual duration of the audio/video when it loads.


<element ondurationchange="myScript">

Attribute Value: This attribute contains a single value script that works when ondurationchange event attribute call. This attribute is supported by <audio> and <video> tags.

Below examples illustrate the ondurationchange attribute in HTML:

Example 1: 


<!DOCTYPE html> 
        HTML ondurationchange Attribute
        <h1 style="color:green">GeeksforGeeks</h1
        <h2>HTML ondurationchange Attribute</h2
        <audio controls ondurationchange="GFGfun()"
        <source src
            function GFGfun() { 
                alert("The audio duration has changed"); 



Example 2: 


<!DOCTYPE html>
            HTML ondurationchange Attribute
            <h1 style="color: green;">GeeksforGeeks</h1>
            <h2>HTML ondurationchange Attribute</h2>
            <video width="400" height="200" controls ondurationchange="GFGfun()">
                <source src=
                        type="video/mp4" />
                <source src=
                        type="video/ogg" />
            function GFGfun() {
                alert("The video duration has changed");



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!