0
Okay, here’s the thing - I’m developing a new personal project, and it’s necessary to control the buttons Previous | Next used at the base Switch/Case
, I’m trying to bring numbers to life. Show him how Active.
On the other hand, everything is visual. The idea presented here is actually to go from a element span
to another, when it is clicked on one of the buttons Previous or Next, by placing the number of tag <span>..</span>
in evidence (detached) from others.
Code
var conta = 0;
var obj = document.getElementsByTagName('span');
switch(conta.toString()){
case '1': obj.[0].className = 'color'; break;
case '2': obj.[1].className = 'color'; break;
case '3': obj.[2].className = 'color'; break;
case '4': obj.[3].className = 'color'; break;
case '5': obj.[4].className = 'color'; break;
}
if (conta == 5) { conta = alert("No limite!"); }
}
span {
padding: 5px;
cursor: pointer;
}
span.color {
color: white;
font-weight: bold;
background-color: dimgray;
}
<center>
<button onclick="ancora(conta--);">« Anterior</button>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<button onclick="ancora(conta++);">Próximo »</button>
</center>
You know what this is about, um Pagination effect is what I try to do (only the visual, aesthetic part). In which I am trying to create with
Switch/Case
Note that this
Switch/Case
a click counter has been implemented for direction to take Back or Forward.
Now what I need at the moment is to know stand out only one number at a time of others, as you click in the arrangement of control buttons.
In his job
ancora
you should, before adding the class (CSS)color
, remove that same class from all elementsspan
.– user21448