Reputation: 100
I am using some of bootstrap popover in my html. I just want to disapear the popover on body click or html click
$(function(){
$('[data="popover"]').popover({
container: 'body',
html: true,
content: function () {
return $($(this).data('popover-content')).removeClass('hide');
}
}).click(function(e) {
e.preventDefault();
});
});
Upvotes: 2
Views: 1035
Reputation: 85528
Use
trigger : "focus"
or
data-trigger="focus"
demo -> http://jsfiddle.net/93nyuqyf/
explained here http://getbootstrap.com/javascript/#popovers-examples, section "Dismiss on next click".
Upvotes: 2
Reputation: 910
Add the data-trigger
attribute to the actual popover, and set it to focus
, like so...
<a href="#" title="Dismissible popover" data-toggle="popover" data-trigger="focus" data-content="Click anywhere in the document to close this popover">Click me</a>
Snippet using this to demonstrate...
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container">
<h3>Popover Example</h3>
<a href="#" title="Dismissible popover" data-toggle="popover" data-trigger="focus" data-content="Click anywhere in the document to close this popover">Click me</a>
</div>
If you're struggling have a read through this page, this was where the answer came from
http://www.w3schools.com/bootstrap/bootstrap_popover.asp
Upvotes: 0