ok, I'm having a really tough time with this.

here's a part of my code (most of this Thanks to Karl, part thanks to
mkmanning, very little thanks to me, lol):

$('a.moveup').click(function(event) {
        var $thisRow = $(this).parents('tr:first');
        var $thisTable = $('#main_table');
        var $rows = $('#main_table tr');
        var $lastRow = $rows[$rows.length-1];

        $thisRow.next().insertBefore($thisRow.prev().prev());
        $thisRow.insertBefore( $thisRow.prev().prev().prev());

        if ($thisRow.is(':nth-child(2)')) {
                $thisRow.find('.moveup').hide();
                $thisRow.next().next().find('.moveup').show();
        }

        if($thisRow.next().next().is($($lastRow))){
                $thisRow.next().next().find('.movedown').hide();
                $thisRow.find('.movedown').show();
        }
        return false;
});

I am trying to do this:

Move Up link: switch two table rows, if one of them becomes the top
row, the Move Up link needs to hide. If one of the becomes the bottom
row, the Move Down link needs to hide.

The table is setup with a table row of data, followed by a table row
of horizontal rule. So, when a table row is moved up, I need to switch
it with the row that is 2 above it. The table data row is actually the
second from the bottom due to the horizontal rule table row that is
beneath it.

If any of this doesn't make sense, I apologize. I can try to explain
it better.

Thanks,

Paul



On Jun 16, 2:14 pm, mkmanning <michaell...@gmail.com> wrote:
> A couple quick examples that might help (there're many more ways):
>
> console.log( $('table tr:last').prev() );
>
> var trow = $('table tr');
> console.log( $(trow[trow.length-2]) );
> console.log( trow.eq(trow.length-2) );
>
> Modify the selectors as needed for multiple/nested tables.
>
> HTH
>
> On Jun 16, 10:46 am, theprodigy <tigerseyet...@gmail.com> wrote:
>
> > I've been trying for a while to alter the second to last row of a
> > table. I've tried several ways. The number of rows is dynamic so I
> > can't hard code a number into nth-child. I used $rowNeeded =
> > $thisRow.parents('table:first').children().children().length - 1 to
> > get the second to last row, but it doesn't seem like I can pass this
> > variable into nth-child either.
>
> > How can I select the second to last row of a table?
>
> > Thanks

Reply via email to