Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tooltip not working despite having JQuery and Bootstrap installed

Seemingly similar questions exist here and here but the answers provided don't address my situation.

I have a Node/Express/Webpack stack on my server on which I've used npm to install Bootstrap 4 alpha 6 along with tether.js, the required dependency for tooltip functionality. In my main JS file, as defined in the webpack config, I have imported tether using and initialized Bootstrap tooltip function using the following snippets:

import "tether";

and:

$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})

Then, in my index.hbs (I'm using handlebars to render my pages), I have the following snippet implementing the tooltip:

<button type="button" class="btn btn-secondary" data-toggle="tooltip" title="Tooltip on top">
    Tooltip on top
</button>

The scripts compile successfully without any error or warning. However, when loading the page in the browser, I get the error saying tooltip is not a function.... This shouldn't be happening, right? I can confirm that JQuery is working fine as the following snippet right below the one initializing tooltip as shown above is rendering without any hiccup:

$('p#some').html('from jquery');

As can be seen below, both JQuery and Tether plugins along with the one for Tooltip have been initiated in my webpack.config.js file:

plugins: [
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
    new ExtractTextPlugin({ filename: "../../public/dist/main.min.css" }),
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery",
      "window.jQuery": "jquery",
      Tether: "tether",
      "window.Tether": "tether",
      Alert: "exports-loader?Alert!bootstrap/js/dist/alert",
      Button: "exports-loader?Button!bootstrap/js/dist/button",
      Carousel: "exports-loader?Carousel!bootstrap/js/dist/carousel",
      Collapse: "exports-loader?Collapse!bootstrap/js/dist/collapse",
      Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown",
      Modal: "exports-loader?Modal!bootstrap/js/dist/modal",
      Popover: "exports-loader?Popover!bootstrap/js/dist/popover",
      Scrollspy: "exports-loader?Scrollspy!bootstrap/js/dist/scrollspy",
      Tab: "exports-loader?Tab!bootstrap/js/dist/tab",
      Tooltip: "exports-loader?Tooltip!bootstrap/js/dist/tooltip",
      Util: "exports-loader?Util!bootstrap/js/dist/util",
    }),
    new webpack.LoaderOptionsPlugin({ postcss: [autoprefixer] }),
  ]

The project files are available as an internal repo here in case it helps.

like image 385
TheLearner Avatar asked Jun 22 '17 14:06

TheLearner


People also ask

How do I show tooltip in bootstrap?

How To Create a Tooltip. To create a tooltip, add the data-toggle="tooltip" attribute to an element. Note: Tooltips must be initialized with jQuery: select the specified element and call the tooltip() method.

How do I enable tooltip in bootstrap 5?

To create a tooltip, add the data-bs-toggle="tooltip" attribute to an element. Note: Tooltips must be initialized with JavaScript to work.

Are Bootstrap tooltips accessible?

As you may know, the Twitter bootstrap tooltips are not accessible (I.E. they are not being read by screen readers).

Which plugin is used to create a tooltip in bootstrap?

The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element.


1 Answers

A couple issues, as i've run into similar problems myself.

1) You need to provide reference to popper.js within the plugins section in webpack.config.js;

Popper: ['popper.js', 'default'],

2) in your main js, import the required plugin;

import 'bootstrap/js/dist/tooltip';

More info here: Bootstrap 4 - Webpack install

like image 89
partypete25 Avatar answered Oct 03 '22 03:10

partypete25