0

I am trying to show an image in the popover,

after i created an element i add attributes to show an popover.

var item = document.createElement('div');

var att2 = document.createAttribute("data-toggle");
var att3 = document.createAttribute("title");
var att4 = document.createAttribute("data-content");
var att5 = document.createAttribute("data-placement");

att4.value = "<img src ='blablabla.png' />;"
att3.value = itemname;
att2.value = "popover";
att5.value = "top"

item.setAttributeNode(att5);
item.setAttributeNode(att2);
item.setAttributeNode(att3);
item.setAttributeNode(att4);

any idea ? the output in the popover content is <img src ='blablabla.png' />;

SOLUTION just add html:true into

 $('[data-toggle="popover"]').popover({html:true,trigger:"hover",container: 'body'}); 
Vega
  • 27,856
  • 27
  • 95
  • 103
onurtore
  • 195
  • 1
  • 11

1 Answers1

0

function addImg(theDiv,theImg) {
  var element  = document.createElement("img");
  element.src = theImg;
  document.getElementById(theDiv).appendChild(element);
}
<div id="myDiv" onclick="addImg('myDiv','https://media1.popsugar-assets.com/files/thumbor/7NnYpYvDfxr_HYUpa4tySashCM8/fit-in/1024x1024/filters:format_auto-!!-:strip_icc-!!-/2017/03/17/915/n/1922398/40d6ad1840bc51bf_GettyImages-89938282/i/1997.jpg')">
Click me to append image
</div>

Is this kinda what you're after? Hard to tell from your explanation.

Daniel Williams
  • 2,195
  • 7
  • 32
  • 53