Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get table row by row index jquery

Tags:

jquery

I want to access row in my table using the row index.

When I try to get the row by is index I get :

Uncaught TypeError: undefined is not a function 

This is my code:

function moveUpMuscle(muscleIdFrom, muscleOrderFrom, index)
{

    if(index == 0)
    {
        alert("Muscle is already at the top of the list");
        return;
    }

    table = $("#muslce_order_table");

    console.log(table == null ? "null" : "not null");

    row = table.rows(index);

    muscleIdTo = row.attr("data-id");
    muscleOrderTo = row.attr("data-order");

    console.log("muscleIdFrom " + muscleIdFrom + " muscleOrderFrom " + muscleOrderFrom);
    console.log("muscleIdTo " + muscleIdTo + " muscleOrderTo " + muscleOrderTo);

}

The error points to this line:

 row = table.rows(index);

In my console the log is "not null" so the table element is not undefined.

like image 473
dasdasd Avatar asked Feb 07 '26 17:02

dasdasd


1 Answers

.rows is not a jQuery method. Change your code to retrieve the row as follows

row = table.find('tr').eq(index);

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!