Skip to content
Related Articles
Open in App
Not now

Related Articles

How to use a div as content for Twitter’s Popover?

Improve Article
Save Article
  • Last Updated : 17 Feb, 2020
Improve Article
Save Article

Twitter’s Popover is a bootstrap component somewhat similar to tool-tip where the highlighting difference is that it is triggered whenever the user clicks on the specified selector. Before we use <div> as the content inside the popover, let us have a look on DOM structure of the popover:

Program: DOM structure of a popover.

<!-- DOM structure template for the popover
     id's and attributes are usually specified
     automatically -->
<div class="popover fade show" 
     style="position: absolute; 
            will-change: transform;
            top: 0px; left: 0px; 
            transform: translate3d(6px, 360px, 0px);"
    <div class="arrow" style="left: 80px;"></div>
    <h3 class="popover-header">Popover Header here</h3>
    <div class="popover-body">Popover Content here</div>


Div inside the popover: By default, we cannot define HTML inside the popover. For that, we will set html option as ‘true’ to allow HTML content inside popover when initializing at the initial phase. Store HTML div content inside a variable initialize that variable as an option for the popover.

  • Syntax:
    $([selector]).popover({ html:true; title:[header]; content:[Content] });
  • Example:

    <!DOCTYPE html>
    <html lang="en">
        <meta charset="utf-8">
        <meta name="viewport"
              content="width=device-width, initial-scale=1">
        <!-- CDN's Required -->
        <link rel="stylesheet" href=
        <script src=
        <script src=
        <script src=
            <div class="container">
                <!-- Data for popover header -->
                <div class="pickHead">
                    <h3 class="text text-success">
                <!-- Data for popover content -->
                <div class="pickData">
                    <div class="text">
                      A computer science portal for Geeks
                <!-- Popover Button -->
                <button class="btn btn-success" 
                  Twitter's popover
            // Pick the div data as required
            var head = "" + $('.pickHead').html();
            var data = "" + $('.pickData').html();
            // Append the html data as the options
            $(document).ready(function() {
                    html: true,
                    title: head,
                    content: data

  • Output:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!