Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tooltips (title="...") won't show in Firefox

I have an element with a title attribute (i.e., a tooltip), wrapped in some container:

<div id="foo">
    <input type="text" title="A tooltip" />
</div>

and I attach a "mousemove" event listener on the container and stop event propagation:

document.getElementById('foo').addEventListener(
    'mousemove',
    function(e) { e.stopPropagation() },
    false
)

This combination of stopping propagation of "mousemoves" on the container now prevents the tooltip from showing up for the inner textbox, in Firefox 2 and upwards. I've tried FF 2[.0.0.20], 3[.0.11], and the latest 3.5 (Windows Server 2003, XP).

As a quick exercise, Firefox users can see this bug in action by running the following equivalent logic as above in your address bar:

javascript:void($('div.vote').mousemove(function(e){ e.stopPropagation() }))

Now mouseover any of the vote up, vote down, or star (favorites) icons for this question. The tooltips no longer appear. Again, in Firefox only.

Does anyone have a workaround for this behavior/bug in Firefox? Has anyone else witnessed this?

Update: It appears Firefox uses "mouse stopped moving" to trigger tooltips in the browser chrome (eg back/forward buttons). See https://bugzilla.mozilla.org/show_bug.cgi?id=82953. However I can't tell if this affects the DOM.

Update: It appears Firefox 10 was the last version exhibiting this behavior. Firefox 11.0 and onwards shows tooltips regardless of event propagation.

Update: Firefox 33(.1) no longer exhibits this behavior.

like image 421
Crescent Fresh Avatar asked Jun 17 '09 02:06

Crescent Fresh


People also ask

How do we add a tooltip to #title?

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 stop the title attribute from displaying tooltip?

There's no way to disable the default browser behaviour, which is to show the title attribute as a "tooltip" in the browser itself. You'll need to resort to some javascript, it could even be as simple as setting the title to blank on hover, and replacing it on mouse out....

What is browser tooltip?

A tooltip is often used to specify extra information about something when the user moves the mouse pointer over an element: Top. Right. Bottom.


1 Answers

I've confirmed this issue. I even tried propagating the event by hand to only the input box using this code:

<div id="foo" title="A tooltip 2"> <input title="A tooltip" type="text" id="bar"/>
</div>
<script type="text/javascript">
document.getElementById('foo').addEventListener(
    'mouseover',
    function(e) {
        e.stopPropagation();
        if (document.createEvent) {
            var inputBox = document.getElementById('bar');
            var evt = document.createEvent("MouseEvents");
            evt.initMouseEvent("mousemove", true, true, window, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, false, false, false, false, null, null);
            inputBox.dispatchEvent(evt);
        }
    },
    false
)
</script>

No dice. However, other mouse events, including mouseover, seem to work fine.

I believe this is a bug. Although it isn't listed in bugzilla, a search does seem to indicate a correlation between the event "mouseover" and tooltips.

You might download the latest nightly build of Firefox here and see if it still is there. If it is, file a bug.

As an alternative, I would see if mouseover might give you the desired effect.

like image 189
Ken Kinder Avatar answered Sep 29 '22 09:09

Ken Kinder