I have had problems getting Bootstrap popovers working with dynamically created elements (but that's for a different question).
So as a workaround, and because the content of these popover elements is not actually dynamic itself, I decided to create a series of hidden elements with popovers that are already in the DOM when the HTML loads. I then planned to clone them using JQuery's clone() and place them where I need them.
The problem is that whilst the new cloned popovers fire, the popover is in the wrong position.
The HTML looks like this
<div style="display: none">
<span id="anid" class="popoverbottom label label-info" data-title="Title" data-content="Content">TAG</span>
</div>
I then register the popover event on the popoverbottom class using code like this:
$(".popoverbottom").popover( {placement : 'bottom', trigger: 'hover', delay: { show: 500, hide: 100 }} );
I then clone the element with the popover on it using JQuery code like this:
e = $('#anid').clone(true);
e.attr('id','anewid');
I then append() the new element dynamically and it appears fine. If I hover over it, a popover fires, but it appears in the top left hand corner of the browser window - half cut off on the left hand side.
If I make the <div> containing the popover elements visible - i.e. remove the display:none, then the popover appears over the original, non-dynamically created DOM element instead of the new cloned one.
This is obviously because when the popover was registered, the popover was tied to the original element. Whilst JQuery's .clone(true) appears to copy the element and the associated events, the original popover position isn't updated.
Is there a way to tell the popover that it's been cloned and it needs to attach the popover to an new element?
Or, would I be better off trying to get dynamically-created popovers working a la this jsFiddle snippet.
As mentioned above, I did try to get this dynamic approach to work but had issues where multiple popovers would stay on the screen and not hide when the mouse moved away - but that's for another question.
Any advice would be appreciated.