How to hide all elements with the lvl attribute greater than 0. Please tell me))

Here is the markup:

 <ul id="list_cat"> <li>Корень каталога</li> <li lvl="0" parent="0" value="10">Hyndai</li> <li lvl="1" parent="10" value="154">Bosch ME17.9.11-12</li> <li lvl="2" parent="154" value="50">Elantra</li> <li lvl="3" parent="50" value="54">AКПП</li> </ul> 

using jquery

  • What does "child attribute greater than 0" mean? - Vyacheslav Danshin
  • @VyacheslavDanshin I apologize, in this case the attribute lvl - Accami

3 answers 3

 $('#list_cat li').filter(function() { return $(this).attr("lvl") > 0; }).hide(); 
  • Thanks It works! - Accami

First you need to select all elements with this attribute.

 $('#list_cat li[lvl]') 

then select from the set only those with the desired value using the filter method

 .filter(function(i,el){ return parseInt($(el).attr('lvl'),10) > 0; }) 

then hide them with the hide method

Example assembly

 $('#list_cat li[lvl]').filter(function(i, el) { return parseInt($(el).attr('lvl'), 10) > 0; }).hide(); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul id="list_cat"> <li>Корень каталога</li> <li lvl="0" parent="0" value="10">Hyndai</li> <li lvl="1" parent="10" value="154">Bosch ME17.9.11-12</li> <li lvl="2" parent="154" value="50">Elantra</li> <li lvl="3" parent="50" value="54">AКПП</li> </ul> 

    To get the child array, go through it using each check the value of lvl and if it satisfies your condition then apply to the hide element