Reputation: 6209
Using jQuery, I want to show li five at a time when I click the show button.
here is my code:
<button class="show">show</button>
<ul>
<li id="Li0">0</li>
<li id="Li1">1</li>
<li id="Li2">2</li>
<li id="Li3">3</li>
<li id="Li4">4</li>
<li id="Li5">5</li>
<li id="Li6">6</li>
<li id="Li7">7</li>
<li id="Li8">8</li>
<li id="Li9">9</li>
<li id="Li10">10</li>
<li id="Li11">11</li>
<li id="Li12">12</li>
<li id="Li13">13</li>
<li id="Li14">14</li>
<li id="Li15">15</li>
</ul>
The script is:
$(".show").click(function(){
$("ul > li:lt(' + (index - 5) + ')+ ").addClass('active');
});
The css is:
ul li{
display:none;
}
.active{
display:inline;
}
Upvotes: 1
Views: 832
Reputation: 2678
$(".show").click(function () {
$("ul li").not(":visible").slice(0, 5).slideDown();
if($("ul li").not(":visible").length == 0)
$(this).hide();
});
Upvotes: 2
Reputation: 76
with your given CSS.
Try this
$(".show").click(function() {
$("ul li:not(.active):lt(5)").addClass('active');
});
Upvotes: 1