How to make Bootstrap popover appear/disappear on hover instead of click?

Bootstrap provides in-built support for making popovers. A popover is a content box that appears when a user triggers a specific event with specified element selector. Here, we will discuss methods to trigger popover using “hover” instead of “click”.

Method 1: Here, we will specify popover trigger in ‘hover’ using jQuery initialization only. We can add title details as well as trigger criteria in popover() function itself as parameters.

  • Program:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Using jQuery initialization only -->
    <!DOCTYPE html>
    <html>
    <head>
        <!-- CDN's required -->
        <link rel="stylesheet" href=
        <script src=
        </script>
        <script src=
        </script>
    </head>
      
    <body>
        <div class="container">
            <center>
                <h1 style="color:green;">GeeksforGeeks</h1>
                <b>
                    Bootstrap popover appear/disappear 
                    on hover instead of click
                </b>
                <br><br>
                <button class="btn btn-success" 
                        data-toggle="popover" 
                        data-content="Computer Science Portal for Geeks" 
                        data-placement="bottom">
                  Hover here!
                </button>
            </center>
        </div>
        <script>
            $('[data-toggle="popover"]').popover({
                title: "GeeksforGeeks",
                trigger: "hover"
            });
        </script>
    </body>
      
    </html>

    chevron_right

    
    

  • Output:

Method 2: Here we will be using ‘data-trigger’ attribute. We can also achieve the same by placing ‘title’ and ‘data-trigger’ as attributes without specifying them as parameters in popover() method.

  • Program:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Using data-trigger attribute -->
    <!DOCTYPE html>
    <html>
    <head>
          
        <!-- CDN's required -->
        <link rel="stylesheet" href=
        <script src=
        </script>
        <script src=
        </script>
    </head>
      
    <body>
        <div class="container">
            <center>
                <h1 style="color:green;">GeeksforGeeks</h1>
                <b>
                    Bootstrap popover appear/disappear 
                    on hover instead of click
                </b>
                <br><br>
                <button class="btn btn-success"
                        title="GeeksforGeeks" 
                        data-toggle="popover" 
                        data-trigger="hover"
                        data-content="Computer Science Portal for Geeks"
                        data-placement="bottom">
                  Hover here!</button>
            </center>
        </div>
        <script>
            $('[data-toggle="popover"]').popover();
        </script>
    </body>
      
    </html>

    chevron_right

    
    

  • Output:


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.