I want to create an automatic counter, which will check what number it is on every second.
For this to happen, keep in mind that it should jump from one element <a>
to another every second.
I am performing tests manually, and then program the self-count.
The whole logic is simple, with each click a descent to an earlier number
Code
el = document.getElementsByTagName('a')
var x = 0, y = 0;
function voltar()
{
if(y == 6 || x == 0)
alert("Limite!");
else {
el[x].style.color = "red";
el[y].style.color = "black";
}
x--;
}
a
{
text-decoration: none;
cursor: pointer;
padding: 3px;
color: black;
}
<a onclick="voltar(x--)" id="menos">Você está no:</a>
<a>1</a>
<a>2</a>
<a>3</a>
<a>4</a>
<a style="color:red">5</a>
Every click on the word You are in: then it should go down to minor / predecessor
NOTE - The previous color should be restored, leaving only the highlighted number in red.