javascript - What is the best way to implement previous and next page logic -


i have webpage huge form (6 pages long). in order make more user friendly, decided break down different sections (div tags). have placed previous , next button on page. on previous click should display previous div tag @ , next should display next div tag. wondering best way implement it? far have function know hardcoded div tag called generalsection. generalsection, have 20 more sections. ideas how should go ? appreciated! :)

$(document).ready(function () {     $("#imgnext").click(function () {      $("#generalsection").hide();                     }); }); 

you iterate through array of elements.

here's simple jsbin should going: https://jsbin.com/siyutumizo/edit?html,js,output

$(document).ready(function() {    var $steps = $('.step');    var currentstep = 0,        nextstep;        $steps.slice(1).hide(); //hide first        $('#next').on('click', function(e) {      e.preventdefault();            nextstep = currentstep + 1;      if (nextstep == $steps.length) {        alert("you reached end");        return;      }      $($steps.get(currentstep)).hide();      $($steps.get(nextstep)).show();      currentstep = nextstep;    });  });
<!doctype html>  <html>  <head>  <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>    <meta charset="utf-8">    <title>js bin</title>  </head>  <body>    <div id="wizard">      <div class="step">1</div>         <div class="step">2</div>       <div class="step">3</div>       <div class="step">4</div>       <div class="step">5</div>       <div class="step">6</div>     </div>    <button id="next">next</button>  </body>  </html>


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -