sisko
sisko

Reputation: 9910

Force hover on HTML element

I need to decieve an HTML element into thinking my cursor id hovering over it.

Can anyone tell me how I might accomplish this? I know I can to something like this $(this).click() to simulate a mouse click. I need an equivalent for hovering.

Thanks

Upvotes: 1

Views: 2594

Answers (1)

Craig M
Craig M

Reputation: 5628

You can use $(el).trigger('mouseover') but that will only execute any hover callbacks you've set up. It won't trigger the browser's hover detection such as for applying css hover rules.

jsFiddle

$(function() {
    $('#s').hover(function() { alert('Wee'); });

    $('#b').click(function() { $('#s').trigger('mouseover'); });
});

Upvotes: 1

Related Questions