javascript - how to hide first five list on click in jQuery -


how hide first 5 list on click , again when click there should hide next 5 list .

<script src="jquery.js"></script> <script>     $(function(){         $(".hidelist").click({             $(this).find("ul li:lt(5)").hide();         })     }) </script> <ul>   <li>this list</li>   <li>this list</li>   <li>this list</li>   <li>this list</li>   <li>this list</li>   <li>this list</li>   <li>this list</li>   <li>this list</li>   <li>this list</li>   <li>this list</li> </ul> <button class="hidelist"></button> 

here go solution https://jsfiddle.net/41xzy6w3/

var cnt = 0;  $('button[class="clickme"]').click(function(){  	cnt++;  	$('ul li:lt(' + (cnt * 5) + ')').hide();  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <ul>    <li>this list - 1</li>    <li>this list - 2</li>    <li>this list - 3</li>    <li>this list - 4</li>    <li>this list - 5</li>    <li>this list - 6</li>    <li>this list - 7</li>    <li>this list - 8</li>    <li>this list - 9</li>    <li>this list - 10</li>  </ul>  <button type="submit" class="clickme">click</button>

on every click, hide 5 elements top.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -