简体   繁体   English

悬停一个班级时使另一个班级活跃

[英]Make another class active while hovering a class

How to make another class active while hovering another class ? 悬停另一个班级时如何使另一个班级活跃? First class is "sidebarIcon__icon-cat_toys" Second class to become active is "sidebarSecond__content sidebar__6". 第一类是“ sidebarIcon__icon-cat_toys”。第二类将成为活动的是“ sidebarSecond__content sidebar__6”。
Here First class is becoming active but not the other one. 在这里,头等舱正在活跃,而另一类则没有。

<script>
    $(".sidebarIcon__icon-cat_toys").hover( function () {
        $(this).addClass("active");
        $(".sidebarSecond__content sidebar__6").addClass("active");
    }, function (){
        $(this).removeClass("active");
        $(".sidebarSecond__content sidebar__6").removeClass("active");
    });
</script>

You need to use .sidebarSecond__content.sidebar__6 this if the classes of other element are sidebarSecond__content and sidebar__6 . 如果其他元素的类是sidebarSecond__contentsidebar__6则需要使用.sidebarSecond__content.sidebar__6 in html we add class="sidebarSecond__content sidebar__6" , but in jquery/css selectors, this is how we select those objects .sidebarSecond__content.sidebar__6 . 在html中,我们添加了class="sidebarSecond__content sidebar__6" ,但是在jquery / css选择器中,这就是我们选择那些对象.sidebarSecond__content.sidebar__6

eg. 例如。

<div class="foo bar">

The above div has two CSS classes foo and bar . 上面的div有两个CSS类foobar So we will use the selector $('.foo.bar') to get the element. 因此,我们将使用选择器$('.foo.bar')来获取元素。

<script>
    $(".sidebarIcon__icon-cat_toys").hover( function () {
        $(this).addClass("active");
        $(".sidebarSecond__content.sidebar__6").addClass("active");
    }, function (){
        $(this).removeClass("active");
        $(".sidebarSecond__content.sidebar__6").removeClass("active");
    });
</script>

I think it's just a typo: .sidebarSecond__content sidebar__6 has a space in the middle, making it a class followed by an element. 我认为这只是一个错字: .sidebarSecond__content sidebar__6在中间有一个空格,使其成为一个类,后跟一个元素。 Shouldn't it be .sidebarSecond__content_sidebar__6 ? 应该不是.sidebarSecond__content_sidebar__6吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM