xxxxxxxxxx
1
<!-- Buttons trigger collapse -->
2
<button
3
class="btn btn-primary mb-3"
4
type="button"
5
data-mdb-ripple-init
6
data-mdb-target="#collapseExample"
7
aria-expanded="false"
8
aria-controls="collapseExample"
9
id="testButton"
10
>
11
Button with data-mdb-target
12
</button>
13
14
<!-- Collapsed content -->
15
<div class="collapse" id="collapseExample">
16
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad
17
squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt
18
sapiente ea proident.
19
</div>
1
1
xxxxxxxxxx
1
let collapsableElements = document.querySelectorAll('.collapse');
2
document.getElementById('testButton').setAttribute('data-mdb-collapse-init', true)
3
if (collapsableElements) {
4
collapsableElements.forEach((collapsableElement) => {
5
const test = mdb.Collapse.getOrCreateInstance(collapsableElement, { toggle: false });
6
test.hide();
7
});
8
}
Console errors: 0