0

How could i hide all li items except one?? I would like to hide all element s of li excepting a particular li item

Will this work??

        $(".divmenu").find('li').css("display", "none");
        $(".divmenu").find('li nth-child(4)').css("color", "red");

Or like this??

       $(".divmenu").find('li:not(nth-child(4))').css("display", "none"); 

This one seems simple but it is not working ..Might be wrong syntax?? Please anybody provide simple and efficient techniques

user3640046
  • 101
  • 1
  • 13

3 Answers3

1
$(".divmenu").not(":nth-child(4)").css("display", "none");
Amit Singh
  • 2,267
  • 4
  • 25
  • 50
  • 1
    I found a better way to do this using `$(".divmenu li").not(":eq(3)").hide();` Note that `:eq()` selector indexes start with zero (0). –  Oct 10 '15 at 17:40
0

Try this:

$(".divmenu").find('li').not(':nth-child(4)').css("display", "none"); 
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
0

try this,will work

<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
<script>
$(function() {


$(".divmenu li").not('li:nth-child(2)').hide();  

}); 
</script>
Mr7-itsurdeveloper
  • 1,631
  • 2
  • 17
  • 24