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?
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.
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" });
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With