Complete the code to select the collapse element by its ID.
const collapseElement = document.querySelector('[1]');
The querySelector method requires a CSS selector string. To select an element by ID, prefix the ID with #. So #myCollapse selects the element with ID myCollapse.
Complete the code to create a Bootstrap Collapse instance for the element.
const bsCollapse = new bootstrap.Collapse([1]);The Bootstrap Collapse constructor expects a DOM element, not a selector string. Since collapseElement already holds the element, pass it directly.
Fix the error in the code to toggle the collapse using the Bootstrap instance.
bsCollapse.[1]();The toggle() method switches the collapse state between shown and hidden. Using show() or hide() only shows or hides respectively, but toggle is needed to switch.
Fill both blanks to add a click event listener to the button that toggles the collapse.
document.querySelector('[1]').addEventListener('[2]', () => { bsCollapse.toggle(); });
The button to toggle the collapse has ID 'toggleButton', so select it with '#toggleButton'. The event to listen for is a 'click' to trigger the toggle.
Fill all three blanks to create a complete toggle setup: select button, add click event, and toggle collapse.
const btn = document.querySelector('[1]'); btn.addEventListener('[2]', () => { bsCollapse.[3](); });
We select the button with ID 'toggleBtn' using '#toggleBtn'. We listen for the 'click' event. On click, we call the toggle() method on the Bootstrap collapse instance to switch its state.
