admin管理员组文章数量:1389818
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?
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?
Share Improve this question asked Oct 19, 2012 at 2:24 tenedortenedor 7818 silver badges16 bronze badges 7- 4 Works fine here: jsfiddle/PSS4x – Tats_innit Commented Oct 19, 2012 at 2:25
-
dont forget the
<script>
tag – yodog Commented Oct 19, 2012 at 2:26 - 1 @Tats_innit that works but it doesn't work onload. At least for my browser. – Steven Commented Oct 19, 2012 at 2:27
- @Tats_innit: Your demo doesn't work for me, but works when you use the underlying events. – I Hate Lazy Commented Oct 19, 2012 at 2:28
- 1 possible duplicate of jQuery: Automatically trigger hover – Felix Kling Commented Oct 19, 2012 at 2:33
2 Answers
Reset to default 7Trigger the 'mouseenter'
or 'mouseleave'
events.
The 'hover'
syntax is a jQuery shortcut for binding 'mouseenter'
and 'mouseleave'
.
You can't trigger CSS pseudo selectors with jQuery. But you can do anything else, such as create a function and have that triggered.
本文标签: javascriptCan39t trigger 39hover39 event with jqueryStack Overflow
版权声明:本文标题:javascript - Can't trigger 'hover' event with jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744720833a2621684.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论