How do you use the Bootstrap JavaScript API?
<div class="collapse" id="c1"><div class="card card-body">Content</div></div>
Live preview
const el = document.getElementById('c1');
const instance = bootstrap.Collapse.getOrCreateInstance(el, { toggle: false });
el.addEventListener('shown.bs.collapse', () => console.log('event: shown.bs.collapse'));
instance.show();
await new Promise(r => setTimeout(r, 600));
console.log('open: ' + el.classList.contains('show'));
Console output (real Chrome)
event: shown.bs.collapse
open: true
See Bootstrap JavaScript.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |