Insert image in Bootstrap Popover

I am using Bootstrap Popver. I have inserted some data in the popover and want to insert a image as well. This is what I have tried.

Code:

var img = '<div id = "image"><img src = "http://news.bbcimg.co.uk/media/images/71832000/jpg/_71832498_71825880.jpg" /></div>';
var button = "<button title = " + obj.hostname + "&#44;&#32;" + gpu.toUpperCase() +
        " data-content = \"" + metric_name[metric] + ":&#32;" + display_val + img + "\"" +
        " data-id=\"" + detailed_summary + "\"" +
        " data-text = \"" + obj.hostname + ", " + gpu.toUpperCase() + ", " + metric_name[metric] + ":&#32;" + display_val + "\"" +
        " class=\"btn " + button_state + " gpu btn-lg open-InfoModal\"" +
        " data-toggle=\"modal\" " +
        " data-html=\"true\" " +
        " rel=\"popover\" " +
        " data-target=\"#hostInfo\" " +
        " href=\"#infoModal\"></button>";

Initialisation:

$('button').popover({
            trigger: "hover",
            placement: get_popover_placement,
            html: true
});

I have seen some examples on Stack Overflow, but it didn't work for me as I want to insert it inside the button declaration.

Answers:

Answer

Make use of the content setting of the popover function:

$('button').popover({
            trigger: "hover",
            placement: get_popover_placement,
            html: true,
            content: img //loads the image inside the popover container
});

DEMO

Answer

I have solved it using the code below.

   button = "<button title = " + obj.hostname + "&#44;&#32;" + gpu.toUpperCase() +
           " data-content = \"" + returnPOContent(metric_name[metric], display_val) + "\"" +
       //" data-content = \"" + metric_name[metric] + ":&#32;" + display_val + "\"" +
        " data-id=\"" + detailed_summary + "\"" +
        " data-text = \"" + obj.hostname + ", " + gpu.toUpperCase() + ", " + metric_name[metric] + ":&#32;" + display_val + "\"" +
        " class=\"btn " + button_state + " gpu btn-lg open-InfoModal\"" +
        " data-toggle=\"modal\" " +
        " data-html=\"true\" " +
        " rel=\"popover\" " +
        " data-target=\"#hostInfo\" " +
        " href=\"#infoModal\"></button>";

function returnPOContent(mName, dVal) {
    var popOverContent = mName + ": " +dVal+"</br><div id='test'><img src='http://news.bbcimg.co.uk/media/images/71832000/jpg/_71832498_71825880.jpg'/></div>"; 

    return popOverContent;
}

    $("button").popover({
            trigger: "hover",
            placement: get_popover_placement,
            html: true
      });

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.