function toggleSections(section1, section2, section3, section4) {
document.getElementById(section1).style.display = "block";
document.getElementById(section2).style.display = "none";
document.getElementById(section3).style.display = "none";
document.getElementById(section4).style.display = "none";
}
function changeButtonStyle(btn1, btn2, btn3, btn4) {
document.getElementById(btn1).className = "btn btn-sm btn-block bluebg noround padd10";
document.getElementById(btn2).className = "btn btn-block btn-sm greyback noround padd10";
document.getElementById(btn3).className = "btn btn-block btn-sm greyback noround padd10";
document.getElementById(btn4).className = "btn btn-block btn-sm greyback noround padd10";
}
.greyback {
background-color: rgb(240, 240, 240) !important;
color: #000000;
}
.bluebg {
background-color: rgba(26, 167, 227, 1.00) !important;
color: #FFFFFF !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="col-12">
<div class="row">
<div class="col-3">
<button id="section1Btn" class="btn btn-block btn-sm lbbg" onclick="toggleSections('opt1','opt2','opt3','opt4'), changeButtonStyle('section1Btn','section2Btn','section3Btn','section4Btn')"> View</button></div>
<div class="col-3"><button id="section2Btn" class="btn btn-block btn-sm greyback" onclick="toggleSections('opt2','opt1','opt3','opt4'), changeButtonStyle('section2Btn','section1Btn','section3Btn','section4Btn')">Add</button></div>
<div class="col-3"> <button id="section3Btn" class="btn btn-block btn-sm greyback" onclick="toggleSections('opt3','opt1','opt2','opt4'), changeButtonStyle('section3Btn','section1Btn','section2Btn','section4Btn')">Modify</button></div>
<div class="col-3"> <button id="section4Btn" class="btn btn-block btn-sm greyback" onclick="toggleSections('opt4','opt1','opt2','opt3'), changeButtonStyle('section4Btn','section1Btn','section2Btn','section3Btn')">Delete</button></div>
</div>
</div>
<div id="opt1">Raj</div>
<div id="opt2">Ashok</div>
<div id="opt3">Manish</div>
<div id="opt4">Trivend</div>
I am experimenting with a JavaScript toggle option.
- The initial state has the first button active (with blue background).
- Initially, all hidden div sections are visible. The names should only appear when their corresponding button is clicked.
- The last button is not functioning properly - neither changing color nor opening the fourth section.
I am learning how to use Bootstrap classes and customized button backgrounds.
Any assistance would be greatly appreciated.