Reputation: 147
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();
});
Upvotes: 1
Views: 101
Reputation: 1636
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>
Upvotes: 1