SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast digitalbart's Avatar
    Join Date
    Apr 2002
    Location
    chicago
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery function pass parameters

    I am trying to remove a title attribute for a link on hover and then add it back on mouse out. I would like to pass var hoverText to the hover out...

    Here is the code I have. Any ideas?


    Code JavaScript:
     
     
        $(".icon a").hover(function() {
          $this = $(this);
          var hoverText = $.data(this, 'title', $this.attr('title'));                              
          $(this).find("em").animate({opacity: "show", top: "-35"}, "slow");
          $(this).find("em").text(hoverText);        
     
          $this.removeAttr('title');       
     
     
        }, function(hoverText) {              
     
          $(this).find("em").animate({opacity: "hide", top: "-45"}, "fast");      
          $(this).attr("title", hoverText); 
     
        });

  2. #2
    SitePoint Enthusiast digitalbart's Avatar
    Join Date
    Apr 2002
    Location
    chicago
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works but it is a global. does anyone know how to make it work without a global?

    Code JavaScript:
        hoverText = '';
        $(".icon a").hover(
        function() {
          $this = $(this);                         
          hoverText = $.data(this, 'title', $this.attr('title'));          
          $(this).find("em").animate({opacity: "show", top: "-35"}, "slow");
          $(this).find("em").text(hoverText);        
          $(this).removeAttr('title');    
        }, function() {        
           $(this).attr("title", hoverText); 
             $(this).find("em").animate({opacity: "hide", top: "-45"}, "fast");          
        });

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    If you set the title attribute in HTML, you won't have to do it in javascript.

    If not, where is the data for that attribute coming from?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by digitalbart View Post
    This works but it is a global. does anyone know how to make it work without a global?
    Could you not just assign the hovertext to a hovertext property of the this keyword?

    Code javascript:
    this.hovertext = ...
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •