<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title> Previous and next button </title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container preNextBg">
<div class="col-md-3 preButton">
<button type="button" class="btn btn-primary" onclick="clickChange('prev')"> Previous </button>
</div>
<div class="col-md-6">
<div class="midArea" id="nextChange"></div>
<div style="margin-top:30px;">
<script>
document.write("Red", ", ", "Darkgreen", ", ", "Mediumvioletred", ", ", "Darkblue", ", ", "Yellow", ", ", "Darkorange", ", ", "Deeppink");
</script>
</div>
</div>
<div class="col-md-3 nextButton">
<button type="button" class="btn btn-primary" onclick="clickChange('next')"> Next </button>
</div>
</div>
</body>
</html>
.preNextBg {
margin-top: 80px;
margin-bottom: 60px;
text-align: center;
}
.preButton {
padding-top: 90px;
}
.midArea{
padding-top: 200px;
border: 1px solid grey;
}
.nextButton {
padding-top: 90px;
}
var allColor = ["red", "darkgreen", "mediumvioletred", "darkblue", "yellow", "darkorange", "deeppink"];
function clickChange(action) {
//console.log(action);
if(action == 'next'){
x = allColor.shift();
allColor.push(x);
document.getElementById("nextChange").style.backgroundColor = x;
}
if(action == 'prev'){
y = allColor.pop();
allColor.unshift(y);
color = allColor.slice(-1)[0];
document.getElementById("nextChange").style.backgroundColor = color;
}
}