On Fri, Dec 5, 2008 at 8:22 PM, Alex Hempton-Smith < [EMAIL PROTECTED]> wrote:
> I'm using this code, and the "title" variable is a local variable in the > hover-over function, and not able to be accessed from the next function - > therefore my tooltip has no content the next time I hover over: > $("#places ul li a").hover(function() { > var title = $(this).attr("title"); > $(this).removeAttr("title") > }, function() { > $(this).attr({ > title: title > }); > }); > > (I've removed my custom tooltip code for clarity and I'm just focussing on > the title stuff here). > > Is there any way I could enclose the whole lot in a function and store the > variable in an enclosing function perhaps? > I recommend using .data(): $("#places ul li a").hover( function() { var a = $(this); a.data("title", a.attr("title")).removeAttr("title"); }, function() { var a = $(this); a.attr({ title: a.data("title") }); }); For more info, see http://docs.jquery.com/Core/data - Richard