1

I have created a function to showing a title text in a separate div, its wotks perfectly, but a have problems with "title" attribute, so i wonna delete it after tooltipp wenn be displayed. And on mouse ou show it agaiin, but the variable tooltipptext is empty... same one an idea?

var tooltipptext;    
$(".infoimg").hover(function(event) {
        tooltipptext = $(this).attr("title");

        showToolTip(event, tooltipptext);
        $(this).attr("title", "");

        return false;       
    });

    $(".infoimg").mouseout(function()   {
        $("#bubble_tooltip").hide();
        $(this).attr("title", tooltipptext);
        return false;
    });
7
  • 2
    What exactly is your question? What doesn't work? Commented Aug 20, 2010 at 13:13
  • how do you know title is empty? Commented Aug 20, 2010 at 13:15
  • $(this).attr("title", tooltipptext); tooltiptext is empty, but it shouldn't be Commented Aug 20, 2010 at 13:16
  • also, the .hover function takes two functions as parameters, the first being onmouseover, and the second being onmouseout. you dont have to have the separate mouseout, just put the function as the second parameter to the .hover call Commented Aug 20, 2010 at 13:16
  • becouse if i hover the object again, that contains no text, also i tryed to alert this variable. Commented Aug 20, 2010 at 13:17

1 Answer 1

4

.hover(), when passed a single functions runs it on both mouseenter and mouseleave, clering the variable because this:

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

runs again after $(this).attr("title", ""); ran already. Instead pass both functions to .hover(), like this:

var tooltipptext;    
$(".infoimg").hover(function() {
    tooltipptext = $(this).attr("title");
    showToolTip(event, tooltipptext);
    $(this).attr("title", "");
}, function()  {
    $("#bubble_tooltip").hide();
    $(this).attr("title", tooltipptext);
});

Or since you're never seeing the title attribute on hover, store it once like this:

$(".infoimg").each(function() {
  var title = $(this).attr("title");
  $(this).data('title', title).attr('title','');
}).hover(function() {      
  showToolTip(event, $.data(this, 'title'));
}, function()  {
  $("#bubble_tooltip").hide();
});

This has the added benefit of working on any number of images :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.