myButton using Bootstrap 5's JavaScript API?<button id="myButton" type="button" class="btn btn-secondary" data-bs-toggle="tooltip" title="Tooltip text">Hover me</button>
new keyword and pass a DOM element, not a selector string.Bootstrap 5 tooltips are initialized by creating a new bootstrap.Tooltip instance and passing a DOM element. Option C correctly uses document.getElementById to get the element and the new keyword to create the tooltip.
Option C passes a selector string instead of a DOM element, which is incorrect. Option C misses the bootstrap. namespace. Option C uses a non-existent init method.
trigger option to 'focus' when initializing a Bootstrap popover?Setting trigger: 'focus' means the popover appears when the element receives keyboard or mouse focus and disappears when it loses focus. This is useful for accessibility and keyboard navigation.
Option A describes the hover trigger, option A describes the click trigger, and option A is not a valid trigger behavior.
const tooltip = new bootstrap.Tooltip(document.querySelector('#btn'));Bootstrap 5 tooltips depend on Popper.js to position the tooltip correctly. If Popper.js is missing, the tooltip will not show and a JavaScript error will appear in the browser console indicating Popper is not found.
Option B is incorrect because the tooltip won't appear at all. Option B is wrong because Popper is required. Option B is too extreme; the page won't crash but the tooltip fails.
btn-popover, which code correctly initializes popovers on all of them?<button class="btn-popover" title="Popover 1">One</button> <button class="btn-popover" title="Popover 2">Two</button> <button class="btn-popover" title="Popover 3">Three</button>
querySelectorAll returns a list, and you need to initialize each element separately.Option D correctly selects all elements with .btn-popover and initializes a new popover instance on each element using forEach.
Option D tries to pass a NodeList directly to the constructor, which expects a single element, causing an error. Option D uses a non-existent init method. Option D tries to call Popover() on an HTMLCollection, which is invalid.
<button id="infoBtn" type="button" class="btn btn-info" data-bs-toggle="tooltip" title="More info">Info</button>
Option A correctly uses aria-describedby to link the button to the tooltip content, improving screen reader support.
Option A is insufficient because the title attribute alone is not always accessible or user-friendly. Option A hides the button from assistive technologies, which is bad. Option A removes the tooltip text from accessibility tools.
