我想切换一行中所选列的第一个子类的类

时间:2015-09-23 08:36:46

标签: jquery css css-selectors

我一直试图在一行中切换所选列的第一个孩子的类 这是html代码:

         <div class="container row each-expertise">
            <div class="col l4 m4 skill-1">
                <div class="circle">
                    <i class="material-icons">phonelink_setup</i>
                </div>
                <h5>Software Development</h5>
                <p class="lead sotenue">If you have a problem to solve or an incredible  to digitally proclaim. I can help you espress it through a Web, Mobile or Desktop application. </p>
                <br class="show-on-med">
            </div>
            <div class="col l4 m4 skill-2">
                <div class="circle">
                   <i class="material-icons">web</i> 
                </div>
                <h5>Web Design and Redesign</h5>
                <p class="lead sotenue">If you need people to be informed about what you do, you need a website. You might also need a redesign if you want more from your website. </p>
            </div>
            <div class="col l4 m4 skill-3">
                <div class="circle">
                    <i class="material-icons">airplay</i>
                </div>
                <h5>I.T | Tech Evangelism</h5>
                <p class="lead sotenue">I am fond of inspiring, encouraging, teaching and bringing developers &amp; I.T guys alike together to rub minds, share skills, solutions and experience. </p>
            </div>
        </div>

这里是javascript

$(document).ready(function() {
    $myskill = $("#expertise .each-expertise .col");
    $myskill.hover(function(){
      $(this).toggleClass("white indigo-text text-darken-2");
      $(this).siblings().find('.circle').toggleClass('circle').toggleClass('circled');
    });

});

但这段代码似乎不起作用

2 个答案:

答案 0 :(得分:2)

删除siblings,只需:

$(this).find('.circle').toggleClass('circle').toggleClass('circled');

Sibling()发现$(this)的所有兄弟元素都排除了元素本身。所以在兄弟姐妹中没有.circle元素。

正如您已经写过的那样,toggleClass可以切换多个类:

toggleClass('circle circled');

最后:

$(this).find('.circle').toggleClass('circle circled');

删除了hover circle类时,它会更好:

$(this).find('.circle, .circled').toggleClass('circle circled');

答案 1 :(得分:1)

Demo

您不想使用兄弟姐妹()来选择其他$state.go($state.current.name, $state.params, { reload: true }); 兄弟姐妹。

您需要定位.col.circle,否则您将离开带有.circled课程的第一个孩子。

circled