Complete the code to initialize all tooltips on the page using Bootstrap 5.
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); var tooltipList = tooltipTriggerList.map(function (el) { return new bootstrap.Tooltip([1]); });
The map function passes each element el to the Tooltip constructor to initialize tooltips on those elements.
Complete the code to initialize a popover on the element with id 'myPopover'.
var popoverTrigger = document.getElementById('myPopover'); var popover = new bootstrap.Popover([1]);
You must pass the element reference to the Popover constructor to initialize it on that element.
Fix the error in the code to properly initialize all popovers on elements with data attribute 'data-bs-toggle="popover"'.
var popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]'); var popoverList = popoverTriggerList.map(function (el) { return new bootstrap.Popover([1]); });
querySelectorAll returns a NodeList, which does not have a map method. You must convert it to an array first or use Array.from. But here, the main fix is to pass each element el to the Popover constructor.
Fill both blanks to initialize all tooltips and popovers on the page.
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[1]')); var tooltipList = tooltipTriggerList.map(function (el) { return new bootstrap.Tooltip(el); }); var popoverTriggerList = [].slice.call(document.querySelectorAll('[2]')); var popoverList = popoverTriggerList.map(function (el) { return new bootstrap.Popover(el); });
data-toggle.Bootstrap 5 uses data-bs-toggle attribute to identify tooltip and popover triggers. So the selectors must match exactly.
Fill all three blanks to create a popover with title 'Info', content 'Hello World', and trigger on focus.
var popover = new bootstrap.Popover(document.getElementById('infoPopover'), { title: [1], content: [2], trigger: [3] });
The popover options require strings for title, content, and trigger. Here, the trigger is set to focus so the popover shows when the element gains focus.
