I have an HTML file which has 3 div and 2 button. Functionality of the page is to traverse between 3 div by clicking the next button on the same page. Apparently I have previous button too to go back to the previous div. I have a jquery function for this functionality. Now, I wanted to hide previous button in div1 and next button in div3. I was not able to find any guidance for this. Please find my div code below
<div id="divs">
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
</div>
<input type="submit" value="Next" id="next">
<input type="submit" value="Previous" id="prev">
Please find my script code below
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#divs div").each(function(e) {
if (e != 0) {
$(this).hide();
}
});
$("#next").click(function(){
if ($("#divs div:visible").next().length != 0)
$("#divs div:visible").next().show().prev().hide();
else {
$("#divs div:visible").hide();
$("#divs div:first").show();
}
return false;
});
$("#prev").click(function(){
if ($("#divs div:visible").prev().length != 0)
$("#divs div:visible").prev().show().next().hide();
else {
$("#divs div:visible").hide();
$("#divs div:last").show();
}
return false;
});
});