bootstrap tutorial - How to insert close button in Bootstrap popover - bootstrap examples - bootstrap templates - bootstrap 3



Answer: Use the Popover's html Option

    You can use the Bootstrap popover's html option to insert the close button inside the popover. Further you can utilize the .popover('hide') method to hide the popover when a user click on the close button. Check out the example below:

    Example

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Bootstrap Popover with Close Button - Wikitechy</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('[data-toggle="popover"]').popover({
            placement : 'top',
            html : true,
            title : 'User Info <a href="#" class="close" data-dismiss="alert">×</a>',
            content : '<div class="media"><a href="#" class="pull-left"><img src="images/avatar-tiny.jpg" class="media-object" alt="Sample Image"></a><div class="media-body"><h4 class="media-heading">Jhon Carter</h4><p>Excellent Bootstrap popover! I really love it.</p></div></div>'
        });
        $(document).on("click", ".popover .close" , function(){
            $(this).parents(".popover").popover('hide');
        });
    });
    </script>
    <style type="text/css">
        .bs-example{
            margin: 200px 150px 0;
        }
        .popover-title .close{
            position: relative;
            bottom: 3px;
        }
    </style>
    </head>
    <body>
    <div class="bs-example">
        <button type="button" class="btn btn-primary" data-toggle="popover">Click Me</button>
    </div>
    </body>
    </html>
    click below button to copy the code. By - Bootstrap tutorial - team

    Related Searches to How to insert close button in Bootstrap popover