How to dismiss Bootstrap popover by clicking outside the popover. Currently it has toggle for open link.
HTML
<div class="widget-rating">
<span class="rateit rating-average"></span>
<a class="btn btn-mini" href="javascript:void(0)"><b class="caret"></b></a>
</div>
Here is js code
element.popoverAnchor.popover({
title: "Rating",
animation: false,
html: true,
content: "Loading...",
placement: "bottom",
trigger: "click"
});
How to dismiss Bootstrap popover by clicking outside the popover. Currently it has toggle for open link.
HTML
<div class="widget-rating">
<span class="rateit rating-average"></span>
<a class="btn btn-mini" href="javascript:void(0)"><b class="caret"></b></a>
</div>
Here is js code
element.popoverAnchor.popover({
title: "Rating",
animation: false,
html: true,
content: "Loading...",
placement: "bottom",
trigger: "click"
});
Share
Improve this question
edited Feb 17, 2014 at 20:16
Jack Bonneman
1,80518 silver badges24 bronze badges
asked Oct 3, 2013 at 11:29
SowmyaSowmya
27k21 gold badges101 silver badges137 bronze badges
2 Answers
Reset to default 6$('body').on('click', function (e) {
$('.popover-link').each(function () {
//the 'is' for buttons that trigger popups
//the 'has' for icons within a button that triggers a popup
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
Reference : http://mattlockyer./2013/04/08/close-a-twitter-bootstrap-popover-when-clicking-outside/
$('body').on('click', function (e) {
$("div.popover").each(function() {
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).prevAll('*:first').popover('hide');
}
});
});
universal modification for any case.. no need to specify class for trigger element