Callback function after tooltip / popover is created with twitter bootstrap?

Solution 1:

Works for tooltip:

var tmp = $.fn.tooltip.Constructor.prototype.show;
$.fn.tooltip.Constructor.prototype.show = function () {
  tmp.call(this);
  if (this.options.callback) {
    this.options.callback();
  }
}

this.$('#selector').tooltip({ 
  placement: 'top', 
  callback: function() { 
    alert('hello') 
  } 
});

Solution 2:

Maybe this wasn't available when the previous answers were given but as of 2016, you can attach events to popovers (functionally equivalent to a callback).

eg

$('#myPopover').on('shown.bs.popover', function () {
  // do something…
})

Events include:

  • show.bs.popover
  • shown.bs.popover
  • hide.bs.popover
  • hidden.bs.popover
  • inserted.bs.popover

Ref bootstrap docs