Thanks for your help and patience Richard!I've made those changes and it all
works and looks a lot cleaner now.
Thanks again,
Alex


On Sat, Dec 6, 2008 at 1:44 AM, Richard D. Worth <[EMAIL PROTECTED]> wrote:

> I prefer $(this).data(...) to $.data(this, ... Other than that, it looks
> good.
>
> Ok, one minor thing. I would change:
>
> $(this).parent().append("<span>" + title + "</span>");
> $("#places ul li span").fadeIn();
>
> to (untested):
>
> $("<span>" + title + "</span>").appendTo($(this).parent()).fadeIn();
>
> - Richard
>
>
> On Fri, Dec 5, 2008 at 8:33 PM, Alex Hempton-Smith <
> [EMAIL PROTECTED]> wrote:
>
>> Obviously that code now has the presentational stuff for the tooltip
>> <span> I create and destroy.
>> Comments on that code would be great :)  This is my first go with
>> javascript at all so...
>>
>> -- Alex
>>
>>
>>
>> On Sat, Dec 6, 2008 at 1:31 AM, Alex Hempton-Smith <
>> [EMAIL PROTECTED]> wrote:
>>
>>> Ah I was just about to post about reading up on .data, here's my current
>>> code which works, will look through yours now to see if you do it better!
>>>
>>> $("#places ul li a").hover(function() {
>>>  var title = $(this).attr("title");
>>> jQuery.data(this, "titleText", title);
>>>  $(this).removeAttr("title")
>>> $(this).parent().append("<span>" + title + "</span>");
>>>  $("#places ul li span").fadeIn();
>>> }, function() {
>>> var title = jQuery.data(this, "titleText");
>>>  $(this).next("span").remove();
>>> $(this).attr({
>>> title: title
>>>  });
>>> });
>>>
>>> -- Alex
>>>
>>>
>>>
>>> On Sat, Dec 6, 2008 at 1:27 AM, Richard D. Worth <[EMAIL PROTECTED]>wrote:
>>>
>>>>
>>>> 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
>>>>
>>>>
>>>
>>
>

Reply via email to