1

jQuery's 'hover' trigger doesn't seem to work. My code is simple:

<div id='el'>Content</div>

// does not work
$('#el').on('hover', function() { console.log('is not triggered'); });
$('#el').trigger('hover');

// works for various strings: 'foo', 'click', 'hove', 'keyup', etc.
$('#el').on('foo', function() { console.log('is triggered'); });
$('#el').trigger('foo');

Any handler I bind to this div with .on responds to .trigger except for the 'hover' event. A handler bound with .on('hover', handler) does respond to me manually hovering on the element, but it does not respond to programmatic triggers. I've tested this in both Chrome and Firefox.

Any ideas? Is this a bug in jQuery?

7
  • 4
    Works fine here: jsfiddle.net/PSS4x Commented Oct 19, 2012 at 2:25
  • dont forget the <script> tag Commented Oct 19, 2012 at 2:26
  • 1
    @Tats_innit that works but it doesn't work onload. At least for my browser. Commented Oct 19, 2012 at 2:27
  • @Tats_innit: Your demo doesn't work for me, but works when you use the underlying events. Commented Oct 19, 2012 at 2:28
  • 1
    possible duplicate of jQuery: Automatically trigger hover Commented Oct 19, 2012 at 2:33

2 Answers 2

7

Trigger the 'mouseenter' or 'mouseleave' events.

The 'hover' syntax is a jQuery shortcut for binding 'mouseenter' and 'mouseleave'.

Sign up to request clarification or add additional context in comments.

1 Comment

This is not working for the jquery version greater than 1.8
1

You can't trigger CSS pseudo selectors with jQuery. But you can do anything else, such as create a function and have that triggered.

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.