Recipe 13.6

Manually Controlling a Popover

HTML elements have a togglePopover method that will show or hide its contents in a popover.

Demo

Hello World!

Code

JavaScript
const popover = document.querySelector('#greeting');
const trigger = document.querySelector('#trigger');

trigger.addEventListener('click', () => {
  popover.togglePopover();
});
HTML
<button type="button" class="btn btn-primary" id="trigger">Show Popover</button>
<div id="greeting" popover="manual">Hello World!</div>
Web API Cookbook
Joe Attardi