Twitter bootstrap 2.3.2 popover stay open while hovering

Twitter bootstrap 2.3.2 popover stay open while hovering

I have a bottom-oriented popover that I’d like to be a bit more forgiving than the default popover, which vanishes as soon as the mouse leaves the trigger.
html: true,
trigger: ‘hover’,
container: ‘#example’,
placement: ‘bottom’,
content: function () {
return ‘

here is some content


I’ve got it to stay open as long as the mouse is over the trigger or the popover content, but that’s tough for the user, since they’ve got to mouse from the trigger element to the arrow to the content without leaving those areas in order to interact with the popover. Two solutions in mind, neither is working:
1) the delay option ought to do this. adding
delay: {hide: 500}
to the popover call leaves the popover open after the mouse leaves, but re-entering the trigger elem or the popover before it disappears does not tell bootstrap to keep the popover open, so goes away at the end of the initial timeout.
2) widen the arrow’s containing element so that the mouse going from trigger element to background between trigger element and popover to popover works (the mouse then would never have left the trigger/element). The following works except the arrow is drawn with overlapping CSS borders, so the background is not transparent:
.popover.bottom .arrow {
left: 0%;

Related:  Bootstrap - Can't click dropdown child menu items on mobile and first click not triggering nav-collapse

The workaround is to hard-wire the mouseover and mouseleave events with jquery, or to replace the overlapping-borders arrow with an image. Better fixes?


Solution 1:

You can handle the show and hide events for the popover:

    html: true,
    trigger: 'hover',
    container: '#example',
    placement: 'bottom',
    content: function () {
        return '<div class="box">here is some content</div>';
    animation: false
    show: function (e) {
        var $this = $(this);

        // Currently hovering popover
        $"hoveringPopover", true);

        // If it's still waiting to determine if it can be hovered, don't allow other handlers
        if ($"waitingForPopoverTO")) {
    hide: function (e) {
        var $this = $(this);

        // If timeout was reached, allow hide to occur
        if ($"forceHidePopover")) {
            $"forceHidePopover", false);
            return true;

        // Prevent other `hide` handlers from executing

        // Reset timeout checker

        // No longer hovering popover
        $"hoveringPopover", false);

        // Flag for `show` event
        $"waitingForPopoverTO", true);

        // In 1500ms, check to see if the popover is still not being hovered
        $"popoverTO", setTimeout(function () {
            // If not being hovered, force the hide
            if (!$"hoveringPopover")) {
                $"forceHidePopover", true);
                $"waitingForPopoverTO", false);
        }, 1500));

        // Stop default behavior
        return false;


Related:  LESS mixin a variable class name

It doesn’t seem like there’s anything built-in for the popover for the functionality you want, so this is what I came up with 🙂

What’s nice is that it only allows handlers to execute if they really should – if the popover is actually being hidden or actually being shown. Also, each instance of a popover is unique from each other, so there is no global trickery going on.

Solution 2:

I have a more generic approach to solving this one, which I’m using myself. It involves overloading the popover’s hide function, checking if the associated tooltip is being hovered over, and reacts appropriately – rather than adding all that event handling & html5 data setting.

(function($) {

    var oldHide = $.fn.popover.Constructor.prototype.hide;

    $.fn.popover.Constructor.prototype.hide = function() {
        if (this.options.trigger === "hover" && this.tip().is(":hover")) {
            var that = this;
            // try again after what would have been the delay
            setTimeout(function() {
                return, arguments);
            }, that.options.delay.hide);
        }, arguments);


Load this after your bootstrap & jQuery sources.

Related:  How to use a Bootstrap 3 glyphicon in an html select