Answers for "html toggle button onclick"

2

toggle button

<button type="button" class="btn btn-primary" data-bs-toggle="button" autocomplete="off">Toggle button</button>
<button type="button" class="btn btn-primary active" data-bs-toggle="button" autocomplete="off" aria-pressed="true">Active toggle button</button>
<button type="button" class="btn btn-primary" disabled data-bs-toggle="button" autocomplete="off">Disabled toggle button</button>
Posted by: Guest on August-25-2021
0

javascript button toggle on off

<div class="form-check form-switch"> <input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/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>
Posted by: Guest on July-18-2021

Browse Popular Code Answers by Language