Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send hover event programmatically

Just a quick question about hover events, How can I send a hover event to an element without the user hovering (programmatically).

example:

// Send hover event
$('#myDiv').sendHoverEvent();

// What to do once hovering
$('#myDiv').hover(console.log('hovering'));
like image 579
Elgoog Avatar asked Jun 03 '11 03:06

Elgoog


2 Answers

Try this:

 $('#myDiv').trigger('mouseenter'); 
like image 106
Andrew Cooper Avatar answered Nov 12 '22 21:11

Andrew Cooper


Hover connects two events. The one you want to trigger is mouseenter.

$('#myDiv').mouseenter();
like image 6
natedavisolds Avatar answered Nov 12 '22 22:11

natedavisolds