Insert image in Bootstrap Popover

user2798227 picture user2798227 · May 13, 2014 · Viewed 7k times · Source

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.

Answer

AyB picture AyB · May 13, 2014

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