Is it possible to hide href title?

2019-01-18 09:52发布

<a href="link.html" title="Titletext">

...is the code.

I need to use the title attribute because of slimbox, but I want to hide the title-text that shows up when hovering the mouse over the link.

Any ideas?

标签: html css slimbox
16条回答
姐就是有狂的资本
2楼-- · 2019-01-18 09:54

jQuery solution - this should be straight forward:

var hiddenTitle; //holds the title of the hovered object
$("li.menu-item > a").hover(function() {
    hiddenTitle = $(this).attr('title'); //stores title
    $(this).attr('title',''); //removes title
}, function() {
    $(this).attr('title',hiddenTitle); //restores title
});
查看更多
【Aperson】
3楼-- · 2019-01-18 09:58

Supposing you are using an image tag in the a tag, you can just use an alternative title for the image (even a space) and that will overwrite the title of the link when you hover over it.

查看更多
孤傲高冷的网名
4楼-- · 2019-01-18 09:59

How about a nice simple:

<a href="link.html" title="Titletext"><span title=" ">text</span></a>

(Better, put something actually useful in the nested title.)

查看更多
手持菜刀,她持情操
5楼-- · 2019-01-18 09:59

This is my jQuery solution, it does everything you need and keep the correct usage of the title attribute. Simply change the selector according to your needs.

/*
 * jQuery remove title browser tooltip
 */
var removeTitleSelector = 'a.removeTitle';
jQuery('body').on('mouseover', removeTitleSelector, function () {
    jQuery(this).data('title', jQuery(this).attr('title'));
    jQuery(this).removeAttr('title');
}).on('mouseout', removeTitleSelector, function () {
    jQuery(this).attr('title', jQuery(this).data('title'));
});
查看更多
戒情不戒烟
6楼-- · 2019-01-18 10:01

No guarantees but depending on how Slimbox works you may be able to include the title then use something like jQuery to remove it a few seconds after page load. Assuming Slimbox indexes the Title attribute and stores it somewhere after reading it in, you may be able to safely remove it after this happens.

查看更多
Viruses.
7楼-- · 2019-01-18 10:01

if you are using jquery, you could do following

$("a").mouseover(function(e){ preventdefault();} );

(haven't tested it though)

查看更多
登录 后发表回答