Stop heading showing on hover with jquery?

I basically store some data in the title attribute of some divs, which probably shouldn't be. In any case, I did it now, and when I aimed at these elements, this information appears in a convenient default hint for browsers.

eg

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

Is there a way to stop this tooltip header functionality from working as usual?

+3
source share
5 answers

You can remove the attribute titlefrom your HTML element and save it elsewhere.

jQuery provides a way to store information attached 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');
    });
});

, $(this).data('title')

+4

.

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

HTML , $().data()

+7

.

, jquery ( title, , , ) script:

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

, :

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

, , , , .
, clueTip ( js). , , , , .

+1

Source: https://habr.com/ru/post/1719770/


All Articles