Vishnu Vishnu - 11 months ago 70
CSS Question

Bootstrap: popover button click

I have used bootstrap popover function, its working now.. but i need to "dismiss" popover box if i click anywhere in the page. please check the code that i have used.

First click on the button then i need to "dismiss" popover box on clicking the black space (now its dismiss only when we clicked on the same button).

$(document).ready(function() {

<link href="" rel="stylesheet" />
<div class="container" style="width:400px; height:400px; background:#000;padding-top:50px;">
<a href="#" title="Header" data-toggle="popover" data-content="Some content" class="btn btn-danger">Click here</a>
<script src=""></script>
<script src=""></script>

Answer Source

This will work

Use below javascript for dismiss popover when outside click

$('body').on('click', function (e) {
    $('[data-toggle="popover"]').each(function () {
        //the 'is' for buttons that trigger popups
        //the 'has' for icons within a button that triggers a popup
        if (!$(this).is( && $(this).has( === 0 && $('.popover').has( === 0) {