[Solved] Jquery to navigate through div [closed]


Here you go.

EDIT

If you want to go to new page after last div just add else statement and add some attribute to send url.

$("#button").on('click', function() {
  var visible = $("[id^=div]:visible"),
    number = parseInt(visible.attr('id').substr(3)) + 1,
    nextDiv = $("#div" + number);
  if (nextDiv.length > 0) {
    visible.hide();
    nextDiv.show();
  } else {
    location.href = $(this).attr("data-href");
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='div1'>
  Content 1
</div>
<div id='div2' style="display:none;">
  Content 2
</div>
<div id='div3' style="display:none;">
  Content 3
</div>
<div id='div4' style="display:none;">
  Content 4
</div>
<div id='div5' style="display:none;">
  Content 5
</div>
<div id='div6' style="display:none;">
  Content 6
</div>
<button id="button" data-href="https://stackoverflow.com/">Next</button>

12

solved Jquery to navigate through div [closed]