Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding title tags on hover

I've looked through previous questions and none of them have really worked for me, i've checked google to and the information I found seems pretty vague, so I thought i'd try here.

Is anyone aware/or have tackle the problem of title tags displaying on hover. I have a series of links and images that will be assigned title tags, however, some of them will be displaying information that would be better off not popping up on hover.

Is there a global function I could use to apply this to all manner of title tags? An example would be as follows:

<a href="service.php" title="services for cars" />

If possible I would like to disable the title "services from cars" appearing on hover.

Thanks again.

like image 534
Aaron Lee Avatar asked Nov 10 '11 10:11

Aaron Lee


People also ask

How do I turn off title tooltip?

To remove the title tooltips globally, add the following code in the Theme Options > JS: jQuery(document). ready(function($){ $('a'). removeAttr("title"); });

How do you hover a title in HTML?

There are two ways you can create a hover text for your HTML elements: Adding the global title attribute for your HTML tags. Creating a tooltip CSS effect using :before selector.


2 Answers

This should work just fine to disable single title:

<a href="service.php" title="services for cars" onmouseover="this.title='';" />

If you need the title afterwards, you can restore it:

<a href="service.php" title="services for cars" onmouseover="this.setAttribute('org_title', this.title'); this.title='';" onmouseout="this.title = this.getAttribute('org_title');" />

This way is not generic though.. to have it applied to all the anchors, have such JavaScript code:

window.onload = function() {
    var links = document.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
        var link = links[i];
        link.onmouseover = function() {
            this.setAttribute("org_title", this.title);
            this.title = "";
        };
        link.onmouseout = function() {
            this.title = this.getAttribute("org_title");
        };
    }
};

Live test case.

Edit: to apply same for more tags (e.g. <img>) first move the core of the code to a function:

function DisableToolTip(elements) {
    for (var i = 0; i < elements.length; i++) {
        var element = elements[i];
        element.onmouseover = function() {
            this.setAttribute("org_title", this.title);
            this.title = "";
        };
        element.onmouseout = function() {
            this.title = this.getAttribute("org_title");
        };
    }
}

Then change the code to:

window.onload = function() {
    var links = document.getElementsByTagName("a");
    DisableToolTip(links);
    var images = document.getElementsByTagName("img");
    DisableToolTip(images);
};
like image 169
Shadow Wizard Hates Omicron Avatar answered Sep 20 '22 13:09

Shadow Wizard Hates Omicron


If your reasoning for using the 'title' tag is for Aria compliance, use aria-label instead.

<a href="service.php" aria-label="services for cars" />
like image 42
Brad Avatar answered Sep 21 '22 13:09

Brad