在悬停#leaderboard时,向#左箭头和#右箭头添加一个类 [英] On hovering #leaderboard, add a class to #left-arrow and #right-arrow
问题描述
对不起,这样一个基本的问题,但我需要知道如何向两个div添加一个类,#left-arrow和#right-arrow。
我明白我可以使用call hover(),但我不确定如何实现它以在另一个元素上添加一个类。
我绝对是Javascript的开始,所以更具体的如何实现它更好!谢谢!
-Judson
您可以使用 .toggleClass()
,如下所示:
$(#leaderboard)。hover(function(){
$(left-arrow,#right-arrow ).toggleClass(myClass);
});
这会在您悬停时添加该类,并在鼠标离开时将其删除。如果您想 添加该类,请 我明白我可以使用call hover(),但我不确定如何实现它以在另一个元素上添加一个类。 只要使用像上面那样的选择器,您不限于在中使用 Sorry for such a basic question, but I need to know how to add a class to two divs, #left-arrow and #right-arrow when I hoverover #leaderboard. I understand I can use the call hover(), but I'm unsure how to implement it to add a class on another element. I'm definitely a beginning with Javascript, so the more specific on how to implement it the better! Thanks! -Judson You can use This adds the class when you hover, removed it when the mouse leaves. If you want to just add the class, then For this part: I understand I can use the call hover(), but I'm unsure how to implement it to add a class on another element. Just use a selector like I have above, you're not restricted to using 这篇关于在悬停#leaderboard时,向#左箭头和#右箭头添加一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! .addClass ()
将可以正常工作,您可以使用 <$ c
$ b
$ b $。
this
任何功能,您可以使用选择器或遍历函数在适当的位置移动。.toggleClass()
, like this:$("#leaderboard").hover(function() {
$("left-arrow, #right-arrow").toggleClass("myClass");
});
.addClass()
will work and you can manually remove it with .removeCass()
later.
this
inside any function, you can use a selector or traverse functions to move around wherever appropriate.