onended event

Definition and usage

The onended event occurs when the audio/video reaches the end.

This event is very useful for messages like 'Thank you for listening', 'Thank you for watching', etc.

Example

Example 1

Execute JavaScript when the audio ends:

<audio onended="myFunction()">

Try it yourself

Example 2

Execute JavaScript when the video ends:

<video onended="myFunction()">

Try it yourself

Syntax

In HTML:

<element onended="myScript">

Try it yourself

In JavaScript:

object.onended = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("ended", myScript);

Try it yourself

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

Technical details

Bubble: Not supported
Can be canceled: Not supported
Event Type: Event
Supported HTML Tags: <audio> and <video>
DOM Version: Level 3 Events

Browser Support

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

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