admin管理员组文章数量:1333186
HTML :
<div class="hover">hover</div>
<div class="click">click</div>
jQuery :
$('.hover').hover(function(){
alert("hovered!");
});
$('.click').click(function(){
$('.hover').hover();
});
This code isn't work , But can I do like $('.hover').hover()
?
Playground : /
PS : I know I can do like
$('.hover').hover(function(){
func();
});
$('.click').click(function(){
func();
});
function func() {
alert("something")
}
But I want to know , Can I hover and call hover function via using "click" function ?
HTML :
<div class="hover">hover</div>
<div class="click">click</div>
jQuery :
$('.hover').hover(function(){
alert("hovered!");
});
$('.click').click(function(){
$('.hover').hover();
});
This code isn't work , But can I do like $('.hover').hover()
?
Playground : http://jsfiddle/wbFLH/
PS : I know I can do like
$('.hover').hover(function(){
func();
});
$('.click').click(function(){
func();
});
function func() {
alert("something")
}
But I want to know , Can I hover and call hover function via using "click" function ?
Share asked May 6, 2013 at 13:23 l2aelbal2aelba 22.2k23 gold badges108 silver badges144 bronze badges1 Answer
Reset to default 8.hover()
uses .mouseenter()
and .mouseleave()
so you have to trigger .mouseenter/.mouseleave
instead.
From jQuery .hover docs
The .hover() method binds handlers for both mouseenter and mouseleave events. You can use it to simply apply behavior to an element during the time the mouse is within the element.
Calling $(selector).hover(handlerIn, handlerOut) is shorthand for:
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
$('.hover').hover(function(){
$('code').append('l');
});
$('.click').click(function(){
$('.hover').mouseenter();
});
EXAMPLE
本文标签: javascriptCan jQuery click to call hover functionsStack Overflow
版权声明:本文标题:javascript - Can jQuery click to call hover functions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742286913a2447092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论