5

if I have bound tooltipster to input elements and to a diferent elements like a div, is there a way I can hide all in a single call?

So far I know I can to this by hand with:

$('form input').tooltipster('hide'); $('#mydiv').tooltipster('hide');

Ivan Juarez
  • 1,413
  • 4
  • 21
  • 30

2 Answers2

15

Tooltipster does add a CSS class to elements that have a tooltip attached : "tooltipstered".

So one technique among others is to call

$('.tooltipstered').tooltipster('close');

Edit: with Tooltipster v4, you can actually do this with the public methods, which is always better. Besides, it also works when you use tooltips with the multiple option, while my previous answer does not:

var instances = $.tooltipster.instances();
$.each(instances, function(i, instance){
    instance.close();
});
Louis Ameline
  • 2,779
  • 1
  • 25
  • 25
4

It's simple, you just need to separate your selectors by comma:

$('form input, #mydiv').tooltipster('hide');

If you don't know exact elements that contain tooltipster you can use filter method:

$('*').filter(function() {
    return $(this).data('tooltipsterNs');
}).tooltipster('hide');
antyrat
  • 27,479
  • 9
  • 75
  • 76
  • Yes I know I can do it that way also, but some of the divs are created dynamically and I cannot pass the names into the tooltipster, that is why I want to close them all in a single call dynamically. In fact is a close all function. – Ivan Juarez Dec 30 '14 at 17:06
  • 1
    Have you tried to use asterisk as your selector? `$('*').tooltipster('hide');` – antyrat Dec 30 '14 at 17:08
  • do you know a way to close them all in a single call I do not know like with qtip2: $('.qtip.ui-tooltip').qtip('hide'); – Ivan Juarez Dec 30 '14 at 17:08
  • Yes and it says that I called "Tooltipster's "hide" method on an uninitialized element". because it will call all elements including those that are not initialized, also using "*" will have some performance issues. – Ivan Juarez Dec 30 '14 at 17:10
  • it will be great to find out which elements are bound witouth knowing their name and at the same time destroy or hide them. – Ivan Juarez Dec 30 '14 at 17:10
  • @IvanJuarez See my updated answer. Unfortunately tooltipster doesn't attach classes or other DOM indicators that can be selected using regular jQuery selectors so only filtering elements by `tooltipsterNs` data property will help there. And yes, it's bad from performance perspective but I don't see any good solution for this that can be achieved in one line – antyrat Dec 30 '14 at 17:21
  • Man you know how to use jQuery correctly, blessings. – Ivan Juarez Dec 30 '14 at 17:26
  • in a further time we will be switching from tooltipster to any other, or simply use bootstrap tooltips. – Ivan Juarez Dec 30 '14 at 17:27