Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show a bootstrap tooltip with an SVG object?

I'm going crazy trying to understand why I can show tooltips on regular HTML elements, but not on D3-generated SVGs: http://jsfiddle.net/nachocab/eQmYX/5/

What am I doing wrong?

$(document).ready(function () {     $("a").tooltip({       'placement': 'bottom'     }); // this works      $("my_circle").tooltip({       'placement': 'bottom'     }); // this does not work }); 
like image 298
nachocab Avatar asked Feb 04 '13 22:02

nachocab


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 use bootstrap 5 tooltips?

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

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.

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).


2 Answers

The problem was that the tooltip that Bootstrap v2.2.2 generates is a <div> that was getting inserted inside the <svg>, which made the browser not render it.

I ended up using the latest development version of Bootstrap Tooltip, which adds a new parameter to determine the container of the tooltip. Now I can do:

$(".my_circle").tooltip({     'container': 'body',     'placement': 'bottom' }); // this works! 

EDIT - One year later

For the record, I dropped the jQuery requirement and I'm now using the excellent d3-tip by Justin Palmer.

like image 86
nachocab Avatar answered Sep 19 '22 21:09

nachocab


Use d3-bootstrap library. This library will provide you alert, popovers, and tooltip functionalities compatible for D3.js You can add following code to your jsFiddle.

Add this in your head part.

<script src="https://github.com/shawnbot/d3-bootstrap/blob/master/d3-bootstrap.js"/> 

Add this in your code part.

d3.selectAll(".my_circle")     .call( d3.tooltip().placement("right") ); 
like image 32
lephix Avatar answered Sep 23 '22 21:09

lephix