JavaScript に問題があり、html ドキュメント内の div の最後の ID を見つける必要があります。見ればわかるのですが、JavaScriptで自動化してほしいです。
<body>
<div id="start">
<div id="1">Text</div>
<div id="2">Text</div>
<div id="3">Text</div>
<div id="4">Text</div>
<div id="5">Text</div>
<div id="6">Text</div>
</div>
</body>
JavaScript:
function setCookie() {
document.cookie = '1';
}
function startPage() {
var cookieValueInt = parseInt(document.cookie);
var secondPage = cookieValueInt + 1;
document.getElementById(document.cookie).style.visibility = 'visible';
document.getElementById(secondPage).style.visibility = 'visible';
if (cookieValueInt == 1) {
document.getElementById('leftarrow').style.visibility = 'hidden';
}
}
function nextPage() {
var cookieValueInt = parseInt(document.cookie);
var secondPage = cookieValueInt + 1;
var newCookieValue = cookieValueInt + 2;
document.getElementById(document.cookie).style.visibility = 'hidden';
document.getElementById(secondPage).style.visibility = 'hidden';
document.getElementById(newCookieValue).style.visibility = 'visible';
document.getElementById(newCookieValue + 1).style.visibility = 'visible';
document.getElementById('leftarrow').style.visibility = 'visible';
document.cookie = newCookieValue;
}
function previousPage() {
var cookieValueInt = parseInt(document.cookie);
var secondPage = cookieValueInt + 1;
var newCookieValue = cookieValueInt - 2;
document.getElementById(document.cookie).style.visibility = 'hidden';
document.getElementById(secondPage).style.visibility = 'hidden';
document.getElementById(newCookieValue).style.visibility = 'visible';
document.getElementById(newCookieValue + 1).style.visibility = 'visible';
document.cookie = newCookieValue;
cookieValueInt = parseInt(document.cookie);
if (cookieValueInt == 1) {
document.getElementById('leftarrow').style.visibility = 'hidden';
}
}