Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery - hide all div except one class

Tags:

jquery

Here is my code :

  <div id="principal" class="classxx">
    <div class="class001 cat2 blabla">
      <div class="class002">
        <div class="class003"></div>
        <div class="class004"></div>
        <div class="class005"></div>
      </div>
    </div>
    <div class="class001 cat3 blabla">
      <div class="class002">
        <div class="class003"></div>
        <div class="class004"></div>
        <div class="class005"></div>
      </div>
    </div>
    <div class="class001 cat1 blabla">
      <div class="class002">
        <div class="class003"></div>
        <div class="class004"></div>
        <div class="class005"></div>
      </div>
    </div>
  </div>

I need a function like :

function showOnlyCat(className){}

If I call showOnlyCat('cat3') I want to see only all the DIVs that have the 'cat3' class (each DIV has multiple classes) and its children of course

And I also need a showAllCat() that shows all the cat1, cat2, cat3... DIVs

Thank you VERY MUCH for your help

like image 958
jrm Avatar asked Dec 04 '22 23:12

jrm


1 Answers

try this :

function showOnlyCat(cat) {
    $('div').not('.'+cat).hide();
}
function showAllCat() {
    $('div').show();
}
like image 167
Prakash Avatar answered Dec 30 '22 15:12

Prakash