Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onclick event on <audio> element

Given the following markup:

<audio controls onclick="alert('hi')">
    <source src="/url/track.mp3" type="audio/mpeg">  
</audio>

I get no response from the onclick event. Seems like all the onclick events are bound to the player controls.

My goal is to run a separate function when the user hits "play".

like image 712
raisa chudinova Avatar asked Nov 22 '25 06:11

raisa chudinova


1 Answers

The onplay attribute is what you're looking for.

<audio onplay="myFunction()">...</audio>

Here's some article on w3schools about it

like image 109
Alexander Mikhalchenko Avatar answered Nov 23 '25 19:11

Alexander Mikhalchenko