子元素上的jQuery切换类 [英] jQuery toggle class on child element

查看:70
本文介绍了子元素上的jQuery切换类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有链接列表,如果单击其中任何一个,它将在单独的div中切换其下方的显示/隐藏文本.如果显示其中之一,它也会隐藏所有其他div 这段代码可以管理它:

I have list of links, and if you click on any of them, it will toggle show/hide text below it in separate div. Also it hides all other divs if one of them is shown This code manages it:

$(document).ready(function(){
$('.targetDiv').hide();
    $('.hideshow').click(function () {
        $('#div' + $(this).attr('target')).toggle('').siblings('.targetDiv').hide('');
});});

这就是链接的样子

<a class="hideshow" target="1"><div class="cennikPlus"><i class="fa fa-plus-square"></i></div>Something something</a>

我需要做的就是改变

fa-plus-square

fa-minus-square

打开和关闭时返回. 我发现"toggleClass"在这种情况下应该很有用,但是我不确定如何在

when open and back, when closed. I found "toggleClass" which should be useful in this case, but I am not sure how to select i inside div inside a

您能帮我吗?

该网站也位于此处

推荐答案

找到<i>并调用toggleClass

Find the <i> and call toggleClass

$(this).find("i").toggleClass("fa-plus-square fa-minus-square")

这篇关于子元素上的jQuery切换类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆