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!
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.
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" });
Many of our components require the use of JavaScript to function. Specifically, they require our own JavaScript plugins and Popper.
Try this:
$('.show-text').popover();
$('.show-text').click(function () {
$('.show-text').not(this).popover('hide');
});
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