Created
May 26, 2024 10:58
-
-
Save momin-riyadh/bbdef9e20674b95da25e9d46ca618711 to your computer and use it in GitHub Desktop.
On active switch toggle collapse show and hide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.min.js --> | |
<!-- https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css --> | |
<div class="form-check form-switch"> | |
<input class="form-check-input" type="checkbox" role="switch" id="user_active" name="user_active"> | |
<label class="form-check-label" for="user_active">Select User Status</label> | |
</div> | |
<div class="collapse" id="myCollapse"> | |
<div class="card card-body"> | |
This div will be shown or hidden based on the toggle switch. | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toggleSwitch = document.getElementById('user_active'); | |
const collapseInstance = new bootstrap.Collapse('#myCollapse', { | |
toggle: false | |
}); | |
toggleSwitch.addEventListener('change', function() { | |
if (this.checked) { | |
collapseInstance.show(); | |
} else { | |
collapseInstance.hide(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment