title: Javascript pages within a page
body: <p>I'm trying to make a 'Next/Previous' system within a page - where it shows one specific item, or 'page', at a time. I can't seem to find a practical solution online. It's currently working, but the code is unprofessional and needlessly long/complicated especially when I want it to have up to 5 pages. </p>
  
  <p>I'm not an experienced JS programmer so please go easy on me!</p>
  
  <p>HTML - </p>
  
  <pre><code>&lt;div id="page1"&gt;Page 1 &lt;button onclick="secondPage()"&gt;Next&lt;/button&gt;&lt;/div&gt;
  &lt;div id="page2"&gt;Page 2 &lt;button onclick="thirdPage()"&gt;Next&lt;/button&gt;&lt;/div&gt;
  &lt;div id="page3"&gt;Page 3 &lt;button onclick="fourthPage()"&gt;Next&lt;/button&gt;&lt;/div&gt;
  &lt;div id="page4"&gt;Page 4&lt;/div&gt;
  </code></pre>
  
  <p>CSS - </p>
  
  <pre><code>.hidden {
  display:none;
  }
  </code></pre>
  
  <p>JS -</p>
  
  <pre><code>        function secondPage() {
              document.getElementById("page1").classList.add('hidden');
              document.getElementById("page2").classList.remove('hidden');
              document.getElementById("page3").classList.add('hidden');
              document.getElementById("page4").classList.add('hidden');
          }
          function thirdPage() {
              document.getElementById("page1").classList.add('hidden');
              document.getElementById("page2").classList.add('hidden');
              document.getElementById("page3").classList.remove('hidden');
              document.getElementById("page4").classList.add('hidden');
          }
          function fourthPage() {
              document.getElementById("page1").classList.add('hidden');
              document.getElementById("page2").classList.add('hidden');
              document.getElementById("page3").classList.add('hidden');
              document.getElementById("page4").classList.remove('hidden');
          }
  </code></pre>
  
  <p>If anyone is able to help me simplify this bit of code with a cleaner and better script that would be much appreciated. Thanks</p>