I have 5 divisions in the html code and after the first division a button "show more" has been placed. I want to fire a jquery command which shows the second division on clicking the button "show more" once and the third division on again clicking the button and so on.
The problem is that i am only able to show the second division and not able to fire the jquery script the second time to show the third division.
below is my Jquery and html.
$(document).ready(function(){
for(i=2;i<=5;i++)
{
$("#"+i).hide();
}
i=2; /* degrade the value of i */
$("button").on("click",function(){
//alert(i);
$("#button").remove();
$("#"+i).show();
var button="<button id='button' class='btn btn-primary'>show more</button>";
$("#"+i).after(button);
i=i+1;
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12" id="1" style="border:1px solid red; height:200px; width:300px;"></div>
<button id='button' class='btn btn-primary'>show more</button>
<div class="col-md-4 col-sm-6 col-xs-12" id="2" style="border:1px solid red; height:200px; width:300px;"></div>
<div class="col-md-4 col-sm-6 col-xs-12" id="3" style="border:1px solid red; height:200px; width:300px;"></div>
<div class="col-md-4 col-sm-6 col-xs-12" id="4" style="border:1px solid red; height:200px; width:300px;"></div>
<div class="col-md-4 col-sm-6 col-xs-12" id="5" style="border:1px solid red; height:200px; width:300px;"></div>
</div><!-- .row -->
</div><!-- .container -->