Whenever I click the right button, the left button appears and when I reach the last page, the right button disappears. However, this behavior is affecting both sections. Is there a way to write separate code for each section?
I managed to make it work by using different IDs but that approach is not ideal. It becomes a coding problem if I have more than 10 rows.
Can this be achieved with jQuery?
HTML
<section>
<div class="left" id="links"><div>
<div class="right" id="rechts"><div>
</section>
<section>
<div class="left" id="btn-l"><div>
<div class="right" id="btn-r"><div>
</section>
CSS
#links {
text-align: center;
width:50px;
height: 100px;
border: 1px solid red;
position: absolute;
left: 10px;
top: 145px;
z-index: 100;
}
#rechts {
text-align: center;
width:50px;
height: 100px;
border: 1px solid red;
position: absolute;
right: 10px;
top: 145px;
z-index: 100;
}
#btn-l {
text-align: center;
width:50px;
height: 100px;
border: 1px solid red;
position: absolute;
left: 10px;
top: 310px;
z-index: 100;
}
#btn-r {
text-align: center;
width:50px;
height: 100px;
border: 1px solid red;
position: absolute;
right: 10px;
top: 315px;
z-index: 100;
}
Jquery
var page1 = 0;
$('.left').hide();
$('.right').click(function(){
$('.left').show();
page1+= 1;
if(page1 >= 3) {
$('.right').hide();
}
});
$('.left').click(function(){
page1-=1;
if(page1<3){
$('.right').show();
}
if(page1 == 0){
$('.left').hide();
}
});