Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Audio file won't play when hovering over image - until a click event takes place on page

I want an audio file (mp3) to play when the user hovers over an image.

The included code won't play the mp3 on hover, until you click somewhere on the page. Then hovering over the image will work. I imagine this is something to do with how browsers handle audio files rather than the code?

This is for a bit of fun and an easter egg on a 404 page. So less bothered about accessibility here as it's ok in this context.

So my question is, is there a workaround for this or do I need to execute the script in a different way?

var test = document.getElementById("test");
test.addEventListener("mouseover", function( event ) {   
  var audio = document.getElementById("audio");
  audio.play();
}, false);
          
<img src="https://www.fillmurray.com/600/400" id="test" />
          
<audio id="audio" preload="auto" src="https://file-examples.com/storage/fe26085c7f62d2ca79a7a30/2017/11/file_example_MP3_700KB.mp3"></audio>
            
       

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!