views:

22

answers:

2

I have the following code:

$("li.item").live('click',function() {
    $('#menu').animate({

    }, 500);
});

Now, I would like to move the character to the li.item you clicked on, but I cannot use $(this) as that would get the #menu item.

I also cannot use li.item as there are 60 of them on the page. Is it possible to pull the specific li.item I clicked on into the animate function?

+2  A: 
$("li.item").live('click',function() {
    // set the current li element to the li_item var
    var li_item = $(this);
    $('#menu').animate({
        // now we can use it in any way we choose
        li_item.addClass('hello');
    }, 500);
});

Try that :-)

ILMV
Yup - that'll do it! Thank you - it's the little easy things that confuse me sometimes. I'll accept in 5 minutes.
Neurofluxation
Glad I could help, don't worry about the little things... I spent this morning trying to debug why one of my selectors wasn't working, I had forgotten to put the # at the front, D'oh!
ILMV
A: 

but I cannot use $(this) as that would get the #menu item.

It would get the clicked item (li.item) not #menu (("li.item").live('click',function() {).

Is it possible to pull the specific li.item I clicked on into the animate function?

Use $(this):

$("li.item").live('click',function() {
    $(this).animate({
    }, 500);
});
Sarfraz