The following works for me in Bootstrap 5 - the same may be applicable in bootstrap 3/4, but double check the docs for your version.
- Require jQuery first.
I've seen some other threads saying you need to require jquery-ui
too - personally i've not had to do this, I can't speak for earlier bootstrap versions.
jQuery has been removed from Bootstrap 5, but it knows to use it if you have it in your project. To do this you must assign jQuery to window.jQuery
- if you try to only assign it to the $
shorthand Bootstrap won't find jQuery (this was the issue for me - see example below of how I use both)
- Next require
@popperjs/core
before bootstrap
Make sure you're using the correct Popper package for your bootstrap version - 4 requires popper.js
, which is not the same as @popperjs/core
Lastly, require bootstrap
If you want tootlips to work on dynamically loaded content (e.g. content that is loaded after you make some future AJAX request), you'll want to make sure you define the selector for tooltips to look for.
window.jQuery = window.$ = require('jquery');
window.Popper = require('@popperjs/core');
require('bootstrap');
$('body').tooltip({
selector: '[data-bs-toggle="tooltip"]',
});
N.B. I'm using packages installed with NPM (i.e. not via CDN), requiring them in my app.js
from node_modules
. But the same should mostly be applicable - especially the order your require dependencies.
- Bootsrtap 5.1.3
- jQuery 3.6.0
- @popperjs/core 2.11.5