I am including tooltip.js and popover.js.
When my markup looks like so:
<button class="popover-dismiss" data-toggle="popover" title="sheen" data-content="<a href="sheen60">60</a>, <a href="sheen80">80</a>"> PDS </button>
with JS
$('.popover-dismiss').popover({ trigger: 'focus', html: 'true' })
Then everything works fine. However, when I change my button
to an a
, it breaks. There are no errors in the console. It just simply does not give the popup.
<a href="javascript://" class="popover-dismiss" data-toggle="popover" title="sheen" data-content="<a href="sheen60">60</a>, <a href="sheen80">80</a>"> PDS </a>
The exact same attributes. Just an anchor instead of a button. I have also tried using a span and that does not appear to work either.
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.
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.
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.
Ok so it turns out there is a bug in Twitter Bootstrap. It has been opened and closed a couple times.
There is currently a work around:
1) Do not use trigger: focus
when initializing bootstrap popovers
2) Instead use data-trigger="focus"
as an attribute to the items which will trigger the popover
3) Items which have a popover will need to have tabindex="-1"
explicitly declared.
Cross-browser working example here: http://jsfiddle.net/v5L7m/3/
I have also confirmed this in a real-world use case scenario.
Edit: @xanderiel noted that tabindex=0
now appears to cause a browser native focus border which is what my original answer called for. They say a tabindex of -1
eliminates this border.
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