【问题标题】:How to remove child attribute when parent class is active父类处于活动状态时如何删除子属性
【发布时间】:2015-07-22 09:46:11
【问题描述】:
 if($("ul.multicb > li").hasClass('active')) {
     $(this).children().removeAttr("href");
 }

我想从包含 .active 类的 li 的子级锚链接中删除 href 属性,但我的代码似乎不起作用。我该怎么做?

【问题讨论】:

    标签: attributes href children


    【解决方案1】:
    if($("ul.multicb > li").hasClass('active')) {
     $(this).find('a').each(function(){
       $(this).removeAttr("href");
    })
    }
    

    【讨论】:

    • 嗯,不幸的是它对我没有用。当我把这个 if($("ul.multicb > li").hasClass('active')) { $("ul.multicb > li > a").removeAttr("href"); } 但随后它只是从所有列表项中删除了 href,我只是希望它从具有活动类的列表项中删除
    • if($("ul.multicb > li").hasClass('active')) { $("ul.multicb > li > a").removeAttr("href"); }
    • 抱歉,我很难格式化代码:/
    • 对不起。我在这里没有得到确切的 html 结构。每个
    • 是否有一个锚标记,或者每个 li 中是否嵌套了多个锚标记?如果您提供 html 结构,将会很有帮助。谢谢
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签