Created
November 29, 2022 20:23
-
-
Save ProfAvery/6bcc95c6236b26fff4ee38fe2a470068 to your computer and use it in GitHub Desktop.
CPSC 349 - Multiple "pages" in a single HTML file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="page1"> | |
<h1>First Page</h1> | |
<p>This page contains some text.</p> | |
</div> | |
<div id="page2" hidden> | |
<h1>Second Page</h1> | |
<p>This page contains a <a href="">link</a>.</p> | |
</div> | |
<div id="page3" hidden> | |
<h1>Third Page</h1> | |
<p>This has some <strong>style</strong>.</p> | |
</div> | |
<button onclick="showNext()">Show Next Page</button> | |
<script> | |
function showNext() { | |
const pages = ['page1', 'page2', 'page3'] | |
const elements = pages.map(id => document.getElementById(id)) | |
const i = elements.findIndex(elt => !elt.hidden) | |
elements[i].hidden = true | |
elements[(i + 1) % elements.length].hidden = false | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment