-2
I’m not getting to put the time because I created a Carousel and wanted to put a 4 seconds interval for iteration .
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Document</title>
</head>
<body>
<div class="container">
<div class="wall wall-1" id="wall-1">
<a href="#wall-3">Voltar</a>
<h1>carrosel numero - 1</h1>
<a href="#wall-2">Avançar</a>
</div>
<div class="wall wall-2" id="wall-2">
<a href="#wall-1">Voltar</a>
<h1>carrosel numero - 2</h1>
<a href="#wall-3">Avançar</a>
</div>
<div class="wall wall-3" id="wall-3">
<a href="#wall-2">Voltar</a>
<h1>carrosel numero - 3</h1>
<a href="#wall-1">Avançar</a>
</div>
</div>
<script>
document.location = "#wall-1";
var x = 1;
setInterval(function () {
x++;
document.querySelector("#wall-1").id = "#wall-1" + x;
if (x == "#wall-3") {
clearInterval();
}
}, 4000);
</script>
</body>
</html>
this error appears Uncaught Typeerror: Cannot set Property 'id' of null at index.html:34
.container {
width: 150px;
height: 150px;
}
.wall {
display: none;
width: 100%;
height: 100%;
}
/* Corzinha de fundo para diferenciar */
.wall-1 {
background-color: #f00;
}
.wall-2 {
background-color: #0f0;
}
.wall-3 {
background-color: #00f;
}
.wall:target {
display: block;
}
on the case as I would put .
– Everton Costa Souza
This line 34 that refers to the id error not found would be which part exactly there of the script?
– LeAndrade
would be that part declared Document.querySelector("#Wall-1"). id = "#Wall-1" + x;
– Everton Costa Souza
Take a table test. The first time you run your function, you look for an element with the
id
wall-1
, then you concatenatex
in theid
of that element, resulting in theid
wall-12
. The second time you run the function, you search again for theid
wall-1
, but thisid
no longer exists, it was changed, so the error.– Andre
I put Wall- without number but also did not work
– Everton Costa Souza
in case I had gone by that logic
– Everton Costa Souza