Bootstrap 5 requires you to select all elements with data-bs-toggle="tooltip" and then create a new Tooltip instance for each element. Option A correctly does this by converting the NodeList to an array and mapping each element to a new Tooltip.
Option A uses the wrong attribute data-toggle and tries to call map directly on a NodeList, which is not an array.
Option A is not a valid Bootstrap method.
Option A tries to create one Tooltip instance for all elements, which is incorrect.
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">Hover me</button>
Option A is missing quotes around the title attribute value, which is invalid HTML and breaks the tooltip.
Option A uses the old data-toggle attribute, which Bootstrap 5 replaced with data-bs-toggle, so the tooltip won't initialize.
Options A, B, and C are all valid syntax, but option A uses double quotes consistently, which is standard.
<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Tooltip below">Hover me</button>
data-bs-placement attribute.The data-bs-placement="bottom" attribute tells Bootstrap to show the tooltip below the button.
Other values like top, left, and right place the tooltip accordingly.
show when visible. Which CSS selector correctly styles only visible tooltips?show class to control visibility.Bootstrap adds the show class to tooltips when they are visible. The selector .tooltip.show targets only those visible tooltips.
Option B uses a non-existent CSS pseudo-class :visible.
Option B looks for an attribute visible, which does not exist.
Option B uses active class, which Bootstrap does not add to tooltips.
Adding tabindex="0" makes the element focusable by keyboard. Showing tooltips on focus as well as hover ensures keyboard users can see the tooltip.
Option C excludes keyboard users.
Option C hides tooltip content from screen readers, reducing accessibility.
Option C removes the native tooltip text, which is important for accessibility.