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 10:02

Override/overlay it with an empty jQuery tooltip?

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-18 10:03

You don't have to use the title attribute with Slimbox. See the Multiple Images example near the top of this page: http://code.google.com/p/slimbox/wiki/MooToolsAPI.

You can simply remove the title attribute from your anchor, and pass the title text (your image's description) to the Slimbox open function, which you would call using the onclick event of your anchor.

查看更多
疯言疯语
4楼-- · 2019-01-18 10:03

Using the idea from David Thomas, you can create a more elegant solution using jQuery:

$('[title]').each(function(){
    $(this).data('original-title', $(this).attr('title'));
}).hover(
    function () { 
        $(this).attr('title','')
    }, function () { 
        $(this).attr('title',$(this).data('original-title'))
});
查看更多
beautiful°
5楼-- · 2019-01-18 10:03

As read on another question, I suggest to switch the "title" attribute to some "data-title" in order to keep it available for screen readers for disabled users. As Lokin said, maintaining the usability of the site to impaired and disabled users should be also something to concern about when developing.

查看更多
戒情不戒烟
6楼-- · 2019-01-18 10:05

the easiest way would be :

after using your slimbox, add the following code below it:

$('*[title]').removeAttr('title');

hope it can help..

查看更多
7楼-- · 2019-01-18 10:09
// Suppress tooltip display for links that have the classname 'suppress'

var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
    if (links[i].className == 'suppress') {
        links[i]._title = links[i].title;
        links[i].onmouseover = function() {
             this.title = '';
        }
        links[i].onmouseout = function() {
             this.title = this._title;
        }
    }}

To quote Aron Rotteveel's answer from the first dupe linked in my comment to the question (Disabling browser tooltips on links and <abbr>s)

查看更多
登录 后发表回答