jquery-6: next, prev
<button class="left">아래</button>
<button class="right">위</button>
<section>
<div class="a active"></div>
<div class="a"></div>
<div class="a"></div>
<div class="a"></div>
<div class="a"></div>
</section>
div.a {
background-color: green;
width: 300px;
height: 50px;
border: 10px solid blue;
}
div.a.active {
border-color: black;
}
$("button.left").click(function() {
let $now = $('div.a.active');
let $next = $now.next();
if($next.length == 0) {
return false
};
$next.addClass('active');
$now.removeClass('active');
})
$("button.right").click(function() {
let $now = $('div.a.active');
let $next = $now.prev();
if($next.length == 0) {
return false
};
$next.addClass('active')
$now.removeClass('active');
})
댓글남기기