<!DOCTYPE html> <html> <body> <audio id="myAudio" controls onended="myFunction()"> <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/ogg"> <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> <p>Play the audio file:</p> <script> function myFunction() { alert("Thank you for listening"); } </script> <p>This example demonstrates how to use the "onended" attribute on an AUDIO element.</p> </body> </html>