开发者

stop the title showing up on hover with jquery?

开发者 https://www.devze.com 2022-12-08 18:25 出处:网络
I basically am storing some data in the title attribute of some divs that I probably shouldn\'t be. Anyways I have done it now and when I hover over these elements this information pops up in the brow

I basically am storing some data in the title attribute of some divs that I probably shouldn't be. Anyways I have done it now and when I hover over these elements this information pops up in the browsers handy default tooltip.

e.g

<div title="blah blah blah">something</div>

Is there a method to stop this tooltip title functionalit开发者_C百科y from working as it normally does?


You can move that data from the title to another attribute and use it from there.

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


Instead of using HTML attributes, you could store the information using $().data()


You can remove the title attribute from your HTML element and store it elsewhere.

jQuery provides a way to store information sticked to HTML elements using $().data().

This should work:

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

You can retrieve it later using $(this).data('title')


Zed and Vincent are right.

If you want it as a jquery function (it removes the title attribute while mouse is over it, and it restores it when it leaves) to be included in a multipage script:

    (function($) {
        $.fn.tooltipSuppress = function() {
            $(this).hover(
                function() {
                    $(this)
                        .data('title', $(this).attr('title'))
                        .removeAttr('title');
                }, 
                function() {
                    $(this).attr('title', $(this).data('title'));
                }
            );
        }
    })(jQuery);

Then just call this to the elements you want it applied:

    $('div,someOtherSelector,ecc').tooltipSuppress();


As others have said, you should probably store the data in another field than the title.
To answer your question about hiding the title hover, have a look at clueTip (or directly at the js). It replaces the standard tooltips with fancy versions, if it can do that I'm sure it can be tweaked to display nothing instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号