3

I had tried looking up on here many different answers to this question and tried using their solutions, but it didn't seem to work, such as this solution: Is it possible to hide href title?

My question is how am I able to hide the title attribute tooltip when the user mouses over the picture? I tried using the <span title=" ">text</span> but it only caused the title tooltip to show the space or the span's title attribute.

Here is my website.

Community
  • 1
  • 1
Abriel
  • 583
  • 1
  • 10
  • 33
  • 1
    Then why have a title attribute? – Brad Mace Dec 19 '10 at 01:59
  • @bemace: The reason I have a title attribute is because for the lightbox I'm using, ColorBox, it reads in the title attribute as the name of the piece within the gallery. I would like to be able to use this feature so others looking at the pictures will tell what each piece is. – Abriel Dec 20 '10 at 01:09
  • Ok, that makes things clearer – Brad Mace Dec 20 '10 at 02:54

5 Answers5

7

I figured out the answer to my question. Thank you Gert G for getting me started! =]

What I did in order to hide the title attribute, was first to put everything into a loop because otherwise, it will take the first link's title and apply it to the picture clicked on:

$("a[rel='portfolio']").each(function(e) {

}

Then, I declared a variable that contains the title to whatever elements you want them applied to:

var title = $(this).attr("title");

Once I declared the variable, I then created a function that hides the title when it's moused over, then adds the title back on when I mouseout on it (for the purpose of having my lightbox, ColorBox).

$(this).mouseover(
        function() {
            $(this).attr('title','');
        }).mouseout(
            function() {
            $(this).attr('title', title);
    });

In order for the title to be viewed when click on, you have to add another function:

$(this).click(
        function() {
            $(this).attr('title', title);
            }
        );

Putting it all together, it looks like this:

$("a[rel='portfolio']").each(function(e) {
    var title = $(this).attr('title');
    $(this).mouseover(
        function() {
            $(this).attr('title','');
        }).mouseout(
            function() {
            $(this).attr('title', title);
    });
    $(this).click(
    function() {
        $(this).attr('title', title);
        }
    );
});

I hope this helps everyone else looking for a similar or this exact solution!

You can check out the changes here.

Abriel
  • 583
  • 1
  • 10
  • 33
1

I was looking for a jquery solution but I am using a javascript solution that works fine for me. I needed the "title" attribute to pass descriptive information about a product / image and within that descriptive information there was basic html tags that were needed. And so whenever someone passed the mouse over the image this mixed code and description will popup. This was less than desirable so I am using the following code so that the "title" information is hidden during mouseover but the title information is still available onclick.

Add this in your link code! Hope this helps someone:

onclick=\"javascript: this.title='description and or html goes here' ;\" 
onMouseOver=\"javascript: this.title='' ;

Cheers!

kleopatra
  • 51,061
  • 28
  • 99
  • 211
1

Thanks Abriel for the solution, I have converted it to YUI 3 and below is the code in case anyone needed it

YUI().use('node', function(Y) { 
    Y.all("a[rel='portfolio']").each(function(node) {
        var title = node.get('title');
        node.on('mouseover', function(ev) {
            ev.target.set('title', ev.target.get('text'));
            ev.target.on('mouseout', function(e) {
                e.target.set('title', title);
            })
        })
        node.on('click', function(ev) {
            ev.target.set('title', title);
        })
    })
})
badrul
  • 71
  • 6
0

Its works like this:

1:Create your own attribute and call it from lightbox

<a href="www.website.com" stitle="hello">click me</a>

2:Rename the title attribute in jquery file to:

getAttribute('stitle')
ElManini
  • 81
  • 6
0

I used it for my tooltip, but it should work even without it.

I nested my link and putted title inside it. Than into nested image I´ve wrote title=" " (with that space).

<a href="http://myweb.com" class="tooltip" id="facebook" title="Sing up to my Newsletter"
<img title=" " src="../img/email.png" alt="email icon" width="32">
</a>

Than, when I hover on my email icon, no title is shown.

Michal
  • 43
  • 8
  • What? It is solution! Author of the question didn´t know that putting single title=" " with space is not enought. I told him why and how to make it. Can´t understand your behavior, sorry. – Michal Jun 22 '14 at 09:29
  • Yes its how I wrote: "Than, when I hover on my email icon, **no title** is shown." For me this nesting simply worked, so I wrote it here. – Michal Aug 02 '15 at 19:47