question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Popover + Tooltip : js error multiple instances with selector option.

See original GitHub issue

Prerequisites

Describe the issue

When using selector option for both popovers and tooltips this way:

new bootstrap.Tooltip(document.body, {
  selector: '[data-bs-toggle="tooltip"]'
});

new bootstrap.Popover(document.body, {
  selector: '[data-bs-toggle="popover"]'
});

We get the following js error (check browser console to see the error):

Bootstrap doesn’t allow more than one instance per element. Bound instance: bs.tooltip.

https://github.com/twbs/bootstrap/blob/520cc8de92ca48d7ac60102d992d7afe9788b239/js/src/dom/data.js#L16-L28

Because we use document.body in both cases.

Reduced test cases

https://codepen.io/florianlacreuse/pen/jOaNzVm

What operating system(s) are you seeing the problem on?

Linux

What browser(s) are you seeing the problem on?

Chrome

What version of Bootstrap are you using?

5.1.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (14 by maintainers)

github_iconTop GitHub Comments

5reactions
HybridSolutionscommented, Mar 17, 2022

Sorry to bring this up again, but using Blazor and the selector option is really required for both the components to work since most of the times elements may not be present on the page. So, if I can’t use this

new bootstrap.Tooltip(document.body, {
            selector: '[data-bs-toggle="tooltip"]'
        });

        new bootstrap.Popover(document.body, {
            selector: '[data-bs-toggle="popover"]'
        });

what is the official alternative since this is the approach mentioned in documentation?

Thank you in advance!

3reactions
pallucommented, Apr 5, 2022

Same problem as @HybridSolutions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap tooltips not working - Stack Overflow
Bootstrap tooltips are expensive because you need to handle mouse events on each of the elements. This is the reason why they haven't...
Read more >
Popovers - Bootstrap
Documentation and examples for adding Bootstrap popovers, like those found in iOS, to any element on your site.
Read more >
Bootstrap JS Popover Reference - W3Schools
Name Type Default Try it animation boolean true Try it container string, or the boolean false false Try it content string "" Try it
Read more >
JavaScript · Bootstrap 3.3.6 Documentation - BootstrapDocs
Don't use data attributes from multiple plugins on the same element. For example, a button cannot both have a tooltip and toggle a...
Read more >
BSN - Native JavaScript for Bootstrap - GitHub Pages
The faster, lighter and more compact version of the Bootstrap JavaScript ... around determining the specific HTMLElement target or setting instance options.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found