Is it possible to hide title when hovering image?

后端 未结 8 958
长情又很酷
长情又很酷 2020-12-21 18:30

This is my code:

\"\"

When I hover that image \"some title\" appears. Is it possib

8条回答
  •  难免孤独
    2020-12-21 18:35

    It's simple enough to remove the title attribute, but 'hiding it' is not possible (so far as I'm aware); in order to remove the title the following should work, though currently untested:

    $('img').hover(
        function(){
            $(this).data('originalTitle',$(this).title());
            $(this).removeAttr('title');
        },
        function(){
            $(this).attr('title',$(this).data('originalTitle');
        });
    

    In the above I've chosen to move the attribute, and then replace it on mouse-out.

    To remove the title permanently:

    $('img').removeAttr('title');
    

    References:

    • attr().
    • data().
    • hover().
    • removeAttr().

提交回复
热议问题