Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter bootstrap popovers close when opening new

I'm not JavaScript wizard, so I'm missing something obvious here I'm sure. I have a table that has multiple links utilizing Twitter Bootstrap's pop-over behavior. I have it where clicking on a link opens the pop-over, and clicking another closes the first, but it becomes glitchy after a few tries, and even starts to close itself. So the question is: How do you properly make pop-overs close once another is opened?

I set up a JSFiddle here (although it doesn't seem to be working at all): http://jsfiddle.net/ZnJ6b/

HTML:

<table>
    <thead>
        <th>Description</th>
        <th>Button</th>
    </thead>
    <tbody>
        <tr>
            <td>Item #1</td>
            <td><a href="#" class="btn show-text" data-toggle="popover" data-placement="right" data-content="Content for item one." title="" data-original-title="Review text">Click for text</a>

            </td>
        </tr>
        <tr>
            <td>Item #2</td>
            <td><a href="#" class="btn show-text" data-toggle="popover" data-placement="right" data-content="Content for item two." title="" data-original-title="Review text">Click for text</a>

            </td>
        </tr>
    </tbody>
</table>

Javascript:

$(this).popover('show');
$('.show-text').click(function () {
    $('.show-text').popover('hide');
});

Thanks in advance for your help to a poor JS n00b!

like image 942
JamieHoward Avatar asked May 07 '13 19:05

JamieHoward


People also ask

How do I use bootstrap 5 popovers?

To create a popover, you need to add the data-bs-toggle="popover" attribute to an element. Whereas, popover's title and its content that would display upon trigger or activation can be specified using the title and data-bs-content attribute respectively. Here is the standard markup for adding a popover to a button.

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" });

Does bootstrap 5 require Popper?

Many of our components require the use of JavaScript to function. Specifically, they require our own JavaScript plugins and Popper.


1 Answers

Try this:

$('.show-text').popover();
$('.show-text').click(function () {
     $('.show-text').not(this).popover('hide');
});
like image 121
palaѕн Avatar answered Sep 20 '22 14:09

palaѕн