Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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:




    <!-- 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>

    
    

  • 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:




    <!-- 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>

    
    

  • Output:


Last Updated : 23 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads