Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap popover trigger: how to set multiple triggers?

I'm trying to use http://twitter.github.io/bootstrap/javascript.html#popovers. I can set the trigger to any one of click | hover | focus | manual. Is there a way to set multiple triggers? I want to use hover and focus.

like image 647
StackOverflowNewbie Avatar asked Jul 03 '13 00:07

StackOverflowNewbie


People also ask

How do I show popover on hover?

Set the trigger option of the popover to hover instead of click , which is the default one. Or with an initialization option: $("#popover"). popover({ trigger: "hover" });

How do you initialize Popovers?

To create a popover, add the data-toggle="popover" attribute to an element. Note: Popovers must be initialized with jQuery: select the specified element and call the popover() method.

How does bootstrap define popover?

A Bootstrap Popover is an attribute in bootstrap that can be used to make any website look more dynamic. Popovers are generally used to display additional information about any element and are displayed with a click of a mouse pointer over that element.


2 Answers

This is easy enough to accomplish by defining your own event handlers and showing/hiding the popover via the API:

HTML:

<input id='no-popover' type='text' />
<input id='has-popover' type='text' placeholder='hover or focus me' />

JavaScript:

var showPopover = function () {
    $(this).popover('show');
}
, hidePopover = function () {
    $(this).popover('hide');
};

$('#has-popover').popover({
    content: 'Popover content',
    trigger: 'manual'
})
.focus(showPopover)
.blur(hidePopover)
.hover(showPopover, hidePopover);

Example: http://jsfiddle.net/Xqx8P/

like image 85
Andrew Whitaker Avatar answered Oct 18 '22 09:10

Andrew Whitaker


When initializing your popover, you may pass multiple triggers; separate them with a space.

   var options = {
       trigger: 'hover focus'
    }

    $('#has-popover').popover(options);
like image 44
Denis Ivanov Avatar answered Oct 18 '22 09:10

Denis Ivanov