Bootstrap – Popovers


Bootstrap – Popovers



”;


This chapter will discuss about popovers in Bootstrap. A popover typically contains additional information, context, or actions related to the triggering element.

The popover may contain text, images, links, buttons, or other content, depending on its purpose and context. Bootstrap provides built-in popover components that can be easily integrated into web applications.


Things to remember while using the popover plug-in:

  • As popovers depend on Popper.js, a third party library, for positioning, you must include popper.min.js before bootstrap.js.
  • As a dependency, the popovers require the popover plugin.
  • You must initialize the popovers first, as popovers are opt-in for performance reasons.
  • A popover will never be shown for a zero-length title and content values.
  • Triggering popovers will not work on hidden elements.
  • Popovers for .disabled or disabled elements must be triggered using a wrapper element.
  • To avoid getting popovers centered between the anchors” overall width, use white-space: nowrap; on the <a>
  • Before removing any element from the DOM, you must hide the popovers corresponding to them.


Enable Popovers

Initialize all the popovers on a page, by their data-bs-toggle attribute



  const popoverTriggerList = document.querySelectorAll(''[data-bs-toggle="popover"]'')
  const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl))


Creating a Popover

Add the data-bs-toggle=”popover” attribute to an element, to create a popover.

  • The data-bs-toggle attribute defines the popover.

  • The title attribute defines the title of the popover

  • The data-content attribute defines the content to be shown in the respective popover.