This is what I've tried, is there a better way of doing it? if so please LMK. Thanks :).
There's a div inside my HTML with an Id of 'content'. Each button have an eventListener and when clicked the eventListener checks the button's dataset and passes it through a dictionary and whatever value they get back will be the page the display inside 'content'.
HTML:
<body>
<div class="content"></div>
</body>
Javascript:
const content = document.querySelector(".content");
const pageOne = `This is page one of the three pages. <button id="next" onclick="showNextPage()" data-next="pageThree">Show Next Page</button> <button id="prev" data-prev="pageOne">Show Previous Page</button>`;
const pageTwo = `Behold the second page of the three pages. <button id="next" onclick="showNextPage()" data-next="pageThree"> Show Next Page</button><button id="prev" data-prev="pageOne">Show Previous Page</button>`;
const pageThree = `Finally the last page, page three of the three pages. <button id="next" onclick="showNextPage()" data-next="pageOne"> Show Next Page</button><button id="prev" data-prev="pageTwo">Show Previous Page</button>`;
content.innerHTML = pageOne;
const dict = {
"pageOne": pageOne,
"pageTwo": pageTwo,
"pageThree": pageThree,
}
function showNextPage() {
let button = document.getElementById("next");
content.innerHTML = dict[button.dataset.next];
}
function showPrevPage() {
let button = document.getElementById("prev");
content.innerHTML = dict[button.dataset.prev];
}