19

Is there a way to disable browser tooltip from displaying when hovering over elements that have attribute 'title' populated? Note that I don't want to remove title content. Here is the code are requested:

  $(document).ready(function() {
     $('a.clickableSticky').cluetip({
         splitTitle: '|',
         showTitle: false,
         titleAttribute: 'description',
         activation: 'click',
         sticky: true,
         arrows: true,
         closePosition: 'title'
     });
 });

and in asp.net

  <ItemTemplate>
     <a class="clickableSticky" href="#"
     title=' <%#((Limit)Container.DataItem).Tip %>'>
     <img src="..\App_Themes\default\images\icons\information.png"/>
     </a>

 </ItemTemplate>
alex
  • 479,566
  • 201
  • 878
  • 984
epitka
  • 17,275
  • 20
  • 88
  • 141
  • You can update your original question to state that - you don't need to post it as a comment :) – Sampson Jun 22 '09 at 15:40
  • What browser is displaying the browser tooltip before Cluetip kicks in? I've tested in Safari, Chrome, IE8 (and 7 compat.), Firefox, and Opera and none had any problems that I could notice. – Dan Herbert Jun 22 '09 at 15:47
  • do you have a link to any of your code? – Shadi Almosri Jun 22 '09 at 16:31
  • What attribute are you using to populate the cluetip content? if you use the title attribute then it will disable the showing of the title when hovering over.... – Shadi Almosri Jun 22 '09 at 16:33
  • I played around with settings and this seems to occur only when cluetip's activation setting is set to click. If it is activated on hover then it works, but if it is activated on click then it shows the tooltip. – epitka Jun 22 '09 at 17:37

7 Answers7

53

You could remove the title attribute on page load.

$(document).ready(function() {
    $('[title]').removeAttr('title');
});

If you need to use the title later, you can store it in the element's jQuery data().

$(document).ready(function() {
    $('[title]').each(function() {
        $this = $(this);
        $.data(this, 'title', $this.attr('title'));
        $this.removeAttr('title');
    });
});

Another option is to change the name of the title attribute to aTitle, or something else that the browser would ignore, and then update any JavaScript to read the new attribute name instead of title.

Update:

An interesting idea you could use is to "lazily" remove the title when hovering over an element. When the user hovers off the element, you can then put the title value back.

This isn't as straightforward as it should be because IE doesn't correctly remove the tooltip on the hover event if you set the title attribute to null or remove the title attribute. However, if you set the tooltip to an empty string ("") on hover, it will remove the tooltip from all browsers including Internet Explorer.

You can use the method I mentioned above to store the title attribute in jQuery's data(...) method and then put it back on mouseout.

$(document).ready(function() {
    $('[title]').mouseover(function () {
        $this = $(this);
        $this.data('title', $this.attr('title'));
        // Using null here wouldn't work in IE, but empty string will work just fine.
        $this.attr('title', '');
    }).mouseout(function () {
        $this = $(this);
        $this.attr('title', $this.data('title'));
    });
});
Dan Herbert
  • 99,428
  • 48
  • 189
  • 219
  • Cool snippet, didn't really think through how I would've done it but I like the easiness of this approach – Andrew G. Johnson Jun 22 '09 at 15:16
  • That is what I am currently doing, storing in description field, but I thought I could have it in title and ignore it – epitka Jun 22 '09 at 15:31
  • If you're wanting to keep the titles there, this won't work. Likely, this will break screen-readers for the visually-impaired. – Sampson Jun 22 '09 at 15:41
  • 1
    As if screen-readers are going to interpret Javascript anyways...? C'mon people! – Josh Stodola Jun 22 '09 at 19:32
  • 1
    Screen readers are quite capable of dealing with JavaScript. However, it is safe to assume they will never trigger the `hover` event so mangling the title on hover would be legitimate. – cweider Oct 28 '10 at 00:02
  • Just implemented the hover idea and it worked marvelously: )) Thanks! – Barka Dec 04 '11 at 05:14
  • Youtube currently uses the hover/remove title, hoverout/replacetitle method. Click any youtube video, click the share tab, inspect the buttons. So if your like me and tend to follow what has proven to be successful, you might take youtube's lead. – Augie Gardner May 16 '13 at 19:03
  • Using this to remove the title tooltip for colorbox (lightbox, fancybox) I found that you will have to restore the title attribute not only on `mouseout`, but also on `click`. Not restoring it on click will not restore it before colorbox starts opening. If not restored, the title won't be loaded within the colorbox title area. – Pim Schaaf Jun 20 '13 at 15:40
8

Here is the modern jQuery way to do it (IMO)...

$('[title]').attr('title', function(i, title) {
    $(this).data('title', title).removeAttr('title');
});

...and of course, reading the title attribute back is done with...

$('#whatever').data('title');
alex
  • 479,566
  • 201
  • 878
  • 984
8

Following Dan Herbert's suggestion above, here is the code:

$(element).hover(
    function () {
        $(this).data('title', $(this).attr('title'));
        $(this).removeAttr('title');
    },
    function () {
        $(this).attr('title', $(this).data('title'));
    });
Barka
  • 8,764
  • 15
  • 64
  • 91
3

You could use jQuery to remove the contents of the title attribte, or move it into some other parameter for later use.

This does mean you lose some accessibility though.

RE: ClueTip A search of Google seems to suggest this is a common problem - is this only happening in IE? ClueTip seems to work as expected in FireFox.

Kothar
  • 6,579
  • 3
  • 33
  • 42
  • I don't want to remove title attribute. I am using 'Cluetip' plugin, and I need the title attribute. Problem is that that ugly yellow tooltipe appears for a second, before cluetip shows up. – epitka Jun 22 '09 at 15:17
  • 3
    @epitka - You could have mentioned that in question. – karim79 Jun 22 '09 at 15:21
  • I am sorry, after I posted it I noticed it and revised it – epitka Jun 22 '09 at 15:36
3
function hideTips(event) {  
    var saveAlt = $(this).attr('alt');
    var saveTitle = $(this).attr('title');
    if (event.type == 'mouseenter') {
        $(this).attr('title','');
        $(this).attr('alt','');
    } else {
        if (event.type == 'mouseleave'){
            $(this).attr('alt',saveAlt);
            $(this).attr('title',saveTitle);
        }
   }
}

$(document).ready(function(){
 $("a").live("hover", hideTips);
});

Hi all. I am using this solution and it works fine in all browsers.

Josh Allen
  • 987
  • 12
  • 30
1

Hack up ClueTip to use a renamed title attribute.

Alfred
  • 21,058
  • 61
  • 167
  • 249
Detect
  • 2,049
  • 1
  • 12
  • 21
0

As I need this functionality to be available during another action (as copy screen or pick color,) my solution contains two functions to be called when that action starts and when it ends:

$.removeTitles = function() {
    $('[title]').bind('mousemove.hideTooltips', function () {
    $this = $(this);
    if($this.attr('title') && $this.attr('title') != '') { 
        $this.data('title', $this.attr('title')).attr('title', '');
    }
  }).bind('mouseout.hideTooltips', function () {
    $this = $(this);
    $this.attr('title', $this.data('title'));
  });
}

$.restoreTitles = function() {
    $('[title]').unbind('mousemove.hideTooltips').unbind('mouseout.hideTooltips');
    $('*[data-title!=undefined]').attr('title', $this.data('title'));
}

MouseEnter cannot be used because other element(s) could lay over the titled element (as an image in a titled div) and than mouseOut will occur as soon as hover over the inner element (the image!)

However when using mouseMove you should pay attention because the event fires multiple times. To avoid wiping the saved data, check first that the title is not empty!

The last line in RemoveTitles, attempts to restore the title from the element from which the mouse did not exit when calling the end on mouseClick or on a shortcut key.

horiatu
  • 356
  • 2
  • 10