Course Content
Bootstrap 5 Alerts
0/1
Progress Bars
0/1
Spinners
0/1
Pagination
0/1
List Groups
0/1
Bootstrap 5 Scrollspy
0/1
Bootstrap
About Lesson

Introduction to Bootstrap 5 Popovers

  • data-bs-toggle=”popover” → Enables the popover functionality
  • title=”Popover Title” → Sets the popover heading
  • data-bs-content=”Popover text” → Defines the popover content
  • data-bs-placement=”top|right|bottom|left” → Specifies popover position

JavaScript Code:

To Enable Popover Functionality in Bootstrap we need to add below JavaScript Code with each Bootstrap Popover Classes:

JavaScript
<!-- Enable Bootstrap 5 Popovers -->
<script>
  document.addEventListener("DOMContentLoaded", function () {
    var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
    var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
      return new bootstrap.Popover(popoverTriggerEl);
    });
  });
</script>

Bootstrap Code:

HTML
<button type="button" class="btn btn-primary" data-bs-toggle="popover" title="Popover Title" data-bs-content="This is a basic popover.">
  Click me
</button>
  • The JavaScript snippet initializes all popovers on the page.
  • title sets the popover header.
  • data-bs-content contains the popover message.
  • data-bs-toggle=”popover” enables Bootstrap popover functionality.