[jQuery] How can i add a callback function the attr() method?

[jQuery] How can i add a callback function the attr() method?


Hi everyone. I understand that you cannot que non-effect jquery methods.
Therefore i need to use a callback function.
Please look at the code i am using for my gallery...
[code]
$(document).ready(function(){
    $("#gallery-thumbs a").click(function(){
        
        var largePath = $(this).attr("href");
        var largeAlt = $(this).attr("title");
        
        $("#img2").fadeTo(1, 0.0, function()
        {
        $("#img2").attr({ src: largePath, alt: largeAlt });    
        $("#img2").fadeTo(1500, 1.0);
        
        });
        
    $('h2').text("" + largeAlt + ""); return false;    
});
});
[/code]
As you can see the code uses a callback function to swap the img src after
the image has faded out, then fades the image back in.
[b]Problem[/b]
The image fades back in before swapping the image. Assumably this is because
it takes a while for the image to load.
What i need to do is use another callback function to only fade the image
back in when the image has been swapped.
[b]Question[/b]
Can someone please tell me how i can add a callback function to the jquery
attr() function?
i.e, something like this...
$("#img2").attr({ src: largePath, alt: largeAlt }, function()
{
$("#img2").fadeTo(1500, 1.0); //fade back in after image swap
} etc...
i have tried several times but failed.
You help would be greatly appriciated.
Thanks.
--
View this message in context: http://www.nabble.com/How-can-i-add-a-callback-function-the-attr%28%29-method--tp18470881s27240p18470881.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.










































    • Topic Participants

    • mg