Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show one popover and hide other popovers

i have several buttons and i need a popover for each.
i want it like this:
when my user click on one of them, i want others to be hidden. so only one popover is shown
check and help me correcting this example plz:

var mycontent='<div class="btn-group"> <button class="btn">Left</button> <button class="btn">Middle</button> <button class="btn">Right</button> </div>' 
$('.btn').popover({     html: true,     content:mycontent,     trigger: 'manual' }).click(function(e) {     $(this).popover('toggle');     e.stopPropagation(); });  $('html').click(function(e) {      $('.btn').popover('hide'); }); 

my html:

<ul>     <li>         <a href="#" class="btn" data-toggle="popover" data-placement="bottom" title="" >Popover</a>     </li>     <li>        <a href="#" class="btn" data-toggle="popover" data-placement="bottom" title="" >Popover</a>      </li> </ul> 

jsfiddle example

adding something like the code bellow solved my problem somehow:

$('.btn').click(function(e) {      $('.btn').popover('hide'); }); 

but by clicking twice on each button it goes wrong

like image 322
PersianMan Avatar asked Apr 22 '13 14:04

PersianMan


People also ask

How do you hide a popover?

To hide the displayed popover, use the popover(“hide”) method.

How do I change my popover placement?

Positioning with Margins So to move the popover more to the left, we can add a negative margin-left, or a positive one to move it further to the right. Likewise, we can move the popover more up by adding a negative margin-top, and down by using a positive value.

How do you show 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 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" });


1 Answers

somehow i created one example for my need. i used this code:

$('.btn').popover();  $('.btn').on('click', function (e) {     $('.btn').not(this).popover('hide'); }); 

check the demo here

and corrected the previous demo i hope it will help someone else

like image 171
PersianMan Avatar answered Oct 04 '22 10:10

PersianMan