jQuery to hide rows that do not have a certain class
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>
I have this function which is close, but not quite开发者_如何学Go 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();
Test
That's not how you close an "a" tag. Should use .
精彩评论