views:

39

answers:

1

Hi there again. This change from mootools drives me crazy.

HTML

<tr class="teamicon">
    <td style="text-align: center;" width="100%" valign="middle">
    //Blahblah
    </td>
  </tr>
  <tr class="teamval">
    <td valign="middle" width="100%">
    //Blahblah
    </td>
  </tr> 

What I want to achieve. When with class "teamicon" is clicked I want to show/hide tr with class teamval with animation. However, I can't make it animate properly. Looks like inside "teamval" must be animated first (or am I wrong?).

My try:

jQuery(document).ready(function(){
$('.teamval').slideUp(400);
$('.teamicon').click(function(){
    if ($(this).next('tr').is(":hidden"))
    {   
        $(this).next('tr.teamval').$('td').slideDown(400, function(){
            $(this).next('tr.teamval').slideDown(400);
        });
    }
    else
    {
        $(this).next('tr.teamval').$('td').slideUp(400, function(){
            $(this).next('tr.teamval').slideUp(400);
        });
    }
});
});

OFC. this is wrong ("$(this).next('tr.teamval').$('td')" returns error in firebug). How can I achieve this?

I can't swap to div though.

+2  A: 

You could do one of:

$(this).next('tr.teamval').slideDown(...) // whole tr

$(this).next('tr.teamval').find('td').slideDown(...) // td descendant

The error is because you are trying to access a $ property on the jQuery element set, which doesn't exist. Instead we can use find, which searches for matching descendants of elements in the current set.

EDIT:

Okay, I think you want:

if ($(this).next('tr').is(":hidden"))
{   
    var nextTeamval = $(this).next('tr.teamval');
    nextTeamval.find('td').slideDown(400, function(){
        nextTeamval.slideDown(400);
    });
}

The only potential problem is if teamval contains a td within a td (nested table). You can try this jsFiddle demo.

Matthew Flaschen
First one works, but as I said, I must first slide td inside this tr. 'tr.teamval > td' and 'tr.teamval td' doesn't work at all. I think that it looks for tr with class teamval which is at the same time td (impossible). Edit: Those with "find" are bad too.
Misiur