简体   繁体   English

删除基于子div的div类

[英]Remove div class based on child div

I have a html like this 我有一个这样的HTML

<div class="accordion_in1 accordion_in acc_active">
    <div class="acc_head" id="removeArrow">
        <div class="acc_icon_expand"></div>
        <a href="/Investor-Relations">Investor Relations</a>
    </div>
    <div class="acc_content" style="display: block;">
        <div class="acc_content_faq1">
            <ul>
                <li>
                    <a href="/Profile" id="ctl00_ctl22_rep1_ctl06_rep2_ctl01_hypLevel2">Profile</a>
                </li>
            </ul>
        </div>
        <div class="acc_content_faq1">
            <ul>
                <li>
                    <a href="/Directors" id="ctl00_ctl22_rep1_ctl06_rep2_ctl02_hypLevel2">Directors</a>
                </li>
            </ul>
        </div>
    </div>
</div>

I need to remove the class acc_head from the second div if there is no div with class acc_content 如果没有acc_content类的div,我需要从第二个div中删除acc_head

I tried to get this in jquery like 我试图像这样在jQuery中获取

<script>
    $(document).ready(function(){

        if ($("accordion_in > div.acc_content").length < 0) {
            $('#removeArrow').removeClass('.acc_head')
        }

                });
 </script>

But I can't able to remove the class.Can any one help Thanks in advance for help 但是我无法删除该课程。能有人帮忙吗?先谢谢您的帮助

If there is no selector with accordion_in > div.acc_content , the length is 0, not a value less than 0. 如果没有accordion_in > div.acc_content选择器,则长度为0,而不是小于0的值。

Try this code. 试试这个代码。

    if (!$("accordion_in > div.acc_content").length) {
        $('#removeArrow').removeClass('.acc_head')
    }

Try this code. 试试这个代码。

if ($("accordion_in > div.acc_content").length) {
    $('#removeArrow').removeClass('acc_head')
}

Try this: 尝试这个:

<script>
    $(document).ready(function(){

        if (($(".acc_active").find("div.acc_content")).length == 0) {
            $('#removeArrow').removeClass('.acc_head');
        }

                });
 </script>

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

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