Check if Bootstrap tooltip is associated with a field?

I am creating Bootstrap tooltips dynamically in the fields, and I would like to check if there is a tooltip in this field so that I can edit the message instead of creating a new tooltip.

I don't see anything like this in the Bootstrap documentation, but I assume there is a way to do this. Does anyone know a way?

+7
source share
3 answers

I also do not see any documentation. But you can check with jQuery if the tooltip has an attribute-original-name. This attribute is added by the plugin when the element is initialized and is used for the text content of the tooltip.

if ($('.example').attr('data-original-title')) { console.log('Tooltip not initialized'); } else { console.log('Tooltip initialized'); // Change the tooltip content $('.example').attr('data-original-title', 'My new title'); } 
+11
source

Using Bootstrap 3:

 var field = $('.example'); if (field.data && field.data('bs.tooltip')) { // tooltip is initialized } else { // tooltip is not initialized } 
+14
source

The method I ended up using just in case it is useful to anyone else,

 var field = $('.example'); if (field.data && field.data('tooltip')) { // tooltip not initalized } else { // it is } 
+3
source

All Articles