У меня проблема с моим javascript, и мне нужно найти последний id div в моем html-документе. Я могу найти его, посмотрев на него, но я хочу, чтобы он был автоматическим в JavaScript.Как найти последний идентификатор в HTML с 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';
}
}
@jantimon Неверно в HTML5. –
@Kolink thanks - не знал, что – jantimon