I have a function which creates popovers in my page, retrieving the content from an AJAX call. During the creation my function changes the popover position (it is page-wide, so I set to 0 the left
attribute and move the arrow to point to my element). Everything works fine the first time, but if I move the mouse out and then in again the popover doesn't move from its default position (and neither does the arrow)
My code:
var last_opened_popover = null
jQuery(document).ready(function(){
jQuery("*[data-poload]").mouseenter(function(){
if (last_opened_popover != null){
last_opened_popover.popover("destroy")
}
var element = jQuery(this)
last_opened_popover = element
var polId = element.data("poload")
jQuery.ajax({
url : my_url,
type : "POST",
data : {
//datas
},
success : function(result){
var supporter_list = compose_supporter_list(result);
var left = element.position().left + 75
element.popover({
content : supporter_list,
html : true,
placement : "bottom",
template : '<div id="shown-popover" class="popover pgsc-popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
})
element.popover("show")
var popover = jQuery("#shown-popover")
popover.css("left", 0)
popover.find(".arrow").css("left", left)
}
})
}).mouseleave(function(){
jQuery(this).popover("destroy")
})
})