I have here a popover with a dynamic content which shows up when I click the popover button. I want to close it when I also click on another area of the page. However, the popover only closes when I click the popover button.
<a class="btn btn-danger" id="btn-post" data-html="true" data-placement="bottom" data-original-title="Post/Lock">
Post/Lock
</a>
I do not set the data-content
on my HTML code. I set it on the js
$("#btn-post").click(function() {
$("#btn-post").attr("data-content", var_dynamic_content);
$('#btn-post').popover('show');
});
I have tried following some codes answered in this post
How to dismiss a Twitter Bootstrap popover by clicking outside?
but nothing there seemed to work for me.
2
Answers
Try this code:
This answer really is similar to the one you mention in your question… Except that it is for Twitter‑Bootstrap (Bootstrap 4).
The difference seems to be that there is no
in
class.I did not test it for all use case… But this snippet works.
CodePen