JSFiddle - React, Tailwind, and code Playground

HTML

<div class="holder">
    <div class="one current">1</div>
    <div class="two">2</div>
    <div class="three">3</div>
</div>
<button>click</button>

CSS

body {
    margin:0;
    padding:0;
}
.holder {
    width: 100px;
    height:100px;
    border:1px solid #000000;
    position: relative;
}

.holder div {
    width: 100px;
    height: 100px;
    position:absolute;
    top:0;
    left:0;
    z-index:0;
}
.holder div.current{
    z-index:1;
}
.one {
    background:red;
}
.two {
    background:green;
}
.three {
    background: blue;
}

JavaScript

$("button").click(function(){
  if($(".holder >div:last-child").hasClass("current")){
     $(".holder >div:last-child").removeClass("current");
     $(".holder >div:first-child").addClass("current");
  }else{
     $(".current").removeClass("current").next().addClass("current");
  }
});