15

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'));

3 Answers 3

15

Try this:

 $('#myDiv').trigger('mouseenter'); 
Sign up to request clarification or add additional context in comments.

2 Comments

For others that are looking for an answer to this I used the above and it didn't work, I made a small change: $('#myDiv').trigger('mouseenter'); and it worked fine, might be a browser issue, not sure. Thanks again @Andrew Cooper
Same here, this should not be the chosen answer unless modified.
6

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

$('#myDiv').mouseenter();

Comments

0

For testing Bootstrap tooltips showing it's better to use:

$('#myDiv').mouseenter();

trigger('hover') simply isn't sufficient to trigger it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.