Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter-bootstrap: How to check if the popover is already showing?

I have created a popover on a dropdown via data attributes:

<select id="timezone_dropdown" data-content="This is the timezone" rel="popover" data-placement="bottom" data-original-title="Time Zone">

And whenever I click on a link button, I would like to show the popover floating over the dropdown.

<a class="btn timezone_help" href="#">Help</a>

In javascript I have defined it like this:

$(document).ready(function () { 
     $('.timezone_help').click(show_timezone_help);     
})

function show_timezone_help(event){
    event.preventDefault(); 
    $('#timezone_dropdown').popover('show');
}

This does the job, however when I click again on the button, it still stays there. Is there a way to check if its already open and hide it instead within the function, or is there a better way?

like image 663
Houman Avatar asked Sep 08 '12 23:09

Houman


People also ask

How do I enable popovers in bootstrap?

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 do you make a popover 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" });

What is the difference between tooltip and popover?

Tooltip: use tooltips to show a short text to respondents when they hover over a word or icon. Popover: use popovers to show a longer text, or when you want to have a link to an external web page. It is shown when the respondent clicks on a word or icon.


1 Answers

Use .popover('toggle'):

function show_timezone_help(event){
    event.preventDefault(); 
    $('#timezone_dropdown').popover('toggle');
}​

And add the attribute data-trigger="manual" to your dropdown.

DEMO.

like image 51
João Silva Avatar answered Sep 28 '22 05:09

João Silva