1

I have an audio file and want that it's playing as soon as the cursor is hovering the div the audio file is placed in.

For any reason its only working with a click function but not with a hover/mouseenter function.

This is working:

$(".interview").on("click",function(){
   $(this).find("#audio")[0].play();
});

This isn't working:

$(".interview").on("hover",function(){
   $(this).find("#audio")[0].play();
});
Dennis
  • 137
  • 1
  • 2
  • 14

1 Answers1

1

Hover is Deprecated as of jQuery 1.8. ref Jquery on hover not working

 $(".interview").hover(function(){
       $(this).find("#audio")[0].play();
  });

(or) use mouseenter event ref https://api.jquery.com/mouseenter/

$(document).on('mouseenter','.interview',function(){
 alert(1)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div class="interview">hover me</div>
Deepak A
  • 1,624
  • 1
  • 7
  • 16
  • Thanks for your answer, but unfortunately this is also not working. :/ – Dennis May 02 '19 at 09:17
  • Thanks. So I also tried the alert and it's working. But not with the audio file playing … any idea? its weird! – Dennis May 02 '19 at 09:26
  • 1
    this is a browser security constraint, and no audio could be played without a click. – Wils May 02 '19 at 09:33