$("#prev").click(function() {
var elems = $('#smallTitle li a');
var prev = elems.filter('.action');
if ( prev.length === 0 ) prev = elems.last();
elems.not( prev.addClass('action') ).removeClass('action');
});
$("#next").click(function() {
var elems = $('#smallTitle li a');
var next = elems.filter('.action').next();
if ( next.length === 0 ) next = elems.first();
elems.not( next.addClass('action') ).removeClass('action');
});
.SwitchURL-small-list{
display:flex;
list-style:none;
font-size: 22px;
font-weight:bold;
}
.SwitchURL-smaill-item{
border-bottom: 0px solid#AE96DA;
padding: 0 1%;
margin-bottom: 1%;
font-size: 20px;
}
.SwitchURL-small-link{
color: #CFC1E9;
margin-right: 15px;
margin-left: 15px;
}
.SwitchURL-small-link:hover{
color: #AE96DA;
}
.SwitchURL-small-link.action {
border-bottom: 2px solid#AE96DA;
color: #AE96DA;
margin-right: 15px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="SwitchURL-small-list" id="smallTitle">
<button id="prev" type="button"> > </button>
<li class="SwitchURL-small-item">
<a href="AA" class="SwitchURL-small-link action" id="SwitchURL0">AA</a>
</li>
<li class="SwitchURL-small-item">
<a href="BB" class="SwitchURL-small-link" id="SwitchURL1">BB</a>
</li>
<li class="SwitchURL-small-item">
<a href="CC" class="SwitchURL-small-link" id="SwitchURL2">CC</a>
</li>
<li class="SwitchURL-small-item">
<a href="DD" class="SwitchURL-small-link" id="SwitchURL3">DD</a>
</li>
<li class="SwitchURL-small-item">
<a href="EE" class="SwitchURL-small-link" id="SwitchURL4">EE</a>
</li>
<button id="next" type="button"> > </button>
</ul>
I have a <li>
element, and inside the <li>
is use href to let user click to the corresponding file,
The <li>
is look like:
Now <li>
selection is "AA", then when I click the next(>) button,
<li>
selection will be dynamic change to "BB", like this image:
or when I click the previous(<) button,
<li>
selection will be dynamic change to "EE", like this image:
And the AA file which is display now will also dynamic change to BB or EE file, too.
Tips: it may be will use removeClass("action")
and addClass("action")
to make <li>
change, but I try many times, it cannot achieve my target.
Can anyone help me? Thank you ;]