xxxxxxxxxx
<div class="form-check form-switch"> <input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault"></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js"></script>
<script>
const btn = document.querySelector(".form-check-input")
label = document.querySelector(".form-check-label");
btn.addEventListener("change", function() {
this.checked ? label.innerHTML = "Button Turned On" :
label.innerHTML = "Button Turned Off"
});
</script>
xxxxxxxxxx
<!DOCTYPE html>
<html>
<head>
<title>Toggle Button</title>
<style>
.toggle {
width: 100px;
height: 40px;
background-color: gray;
border-radius: 20px;
display: flex;
align-items: center;
cursor: pointer;
user-select: none;
}
.toggle.active {
background-color: green;
}
</style>
</head>
<body>
<div id="toggleButton" class="toggle" onclick="toggle()"></div>
<script>
function toggle() {
var toggleButton = document.getElementById("toggleButton");
toggleButton.classList.toggle("active");
}
</script>
</body>
</html>