This should work in Bootstrap 4:
$("#my-popover-trigger").popover({_x000D_
template: '<div class="popover my-popover-content" role="tooltip"><div class="arrow"></div><div class="popover-body"></div></div>',_x000D_
trigger: "manual"_x000D_
})_x000D_
_x000D_
$(document).click(function(e) {_x000D_
if ($(e.target).closest($("#my-popover-trigger")).length > 0) {_x000D_
$("#my-popover-trigger").popover("toggle")_x000D_
} else if (!$(e.target).closest($(".my-popover-content")).length > 0) {_x000D_
$("#my-popover-trigger").popover("hide")_x000D_
}_x000D_
})
_x000D_
Explanation: