jQuery隐藏没有特定类的行 [英] jQuery to hide rows that do not have a certain class

查看:52
本文介绍了jQuery隐藏没有特定类的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下psudeo html.我需要编写一些jquery来隐藏任何不包含具有锚标记的表的行,该表具有特定类'FacetItemsActive'.

I have the following psudeo html. I need to write some jquery which hides any rows which do not contain a table which has an anchor tag with a certain class 'FacetItemsActive'.

<table >
  <tr>
    <td>
     <table>
       <tr>
         <td><a class='FacetItemsActive'/></td>
       </tr>
     </table>
    </td>
  </tr>
  <tr>
    <td>
normal content
    </td>
  </tr>
  <tr>
    <td>
normal content
    </td>
  </tr>
</table>

我有一个接近但不完全存在的功能.你们的jQuery大师都可以帮我吗?

I have this function which is close, but not quite there. Can any of you jquery gurus help me?

function eiaHideNonSelectedFacets(){
    // find the parent facet table
    // find children tr of that table, and hide any rows that do not contain the class 'FacetItemsActive'
    $('.FacetItemsActive').closest('table[facet]').find('tr').each(function(){

        if (! $(this).is('.FacetItemsActive')){
            $(this).hide();
        }
    });
}

推荐答案

$("tr:not(:has('.FacetItemsActive'))").hide();

测试

这篇关于jQuery隐藏没有特定类的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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