A. The modal with title and content appears on top of the page
B. Nothing happens because the modal is missing the show class
C. The page reloads because the button has no type
D. An error appears because aria-hidden is true
Solution
Step 1: Check button attributes for modal trigger
The button has data-bs-toggle="modal" and data-bs-target="#myModal", so it triggers the modal with ID myModal.
Step 2: Understand modal structure and behavior
The modal has correct structure and Bootstrap JS will add the show class dynamically to display it. aria-hidden="true" is default and toggled automatically.
Final Answer:
The modal with title and content appears on top of the page -> Option A
Quick Check:
Modal triggers show modal content on click [OK]
Hint: Modal shows on click if data-bs-toggle and data-bs-target are correct [OK]
Common Mistakes:
Thinking modal needs show class initially
Confusing aria-hidden attribute as an error
Assuming button reloads page without type="button"
4. Identify the error in this modal trigger button code:
The value must be a CSS selector with # for ID. Here it is missing the # before myModal.
Step 2: Verify other attributes
Button type="button" is recommended but not an error. data-bs-toggle is correct for Bootstrap 5+. Button can be outside modal.
Final Answer:
Missing # in data-bs-target value -> Option B
Quick Check:
Modal target needs #id selector [OK]
Hint: Always prefix modal ID with # in data-bs-target [OK]
Common Mistakes:
Omitting # in data-bs-target
Confusing Bootstrap 4 and 5 attribute names
Thinking button must be inside modal
5. You want a modal that opens when a link is clicked and closes when the user presses Escape or clicks outside. Which is the correct minimal setup for the link and modal?
hard
A. <button data-bs-toggle="modal" data-bs-target="#myModal">Open</button> and modal with data-bs-keyboard="false"
B. <a href="#myModal" data-toggle="modal">Open</a> and modal with tabindex="0"
C. <a href="#" data-bs-toggle="modal" data-bs-target="myModal">Open</a> and modal with tabindex="-1" only
D. <a href="#" data-bs-toggle="modal" data-bs-target="#myModal">Open</a> and modal with tabindex="-1" and data-bs-backdrop="true"
Solution
Step 1: Confirm trigger element setup
Using an anchor with href="#", data-bs-toggle="modal", and data-bs-target="#myModal" correctly triggers the modal.
Step 2: Check modal attributes for accessibility and behavior
Modal needs tabindex="-1" for focus management and data-bs-backdrop="true" (default) to close on outside click and Escape key.
Final Answer:
Anchor with data-bs-toggle and data-bs-target plus modal with tabindex="-1" and data-bs-backdrop="true" -> Option D