views:

145

answers:

3

Hi, I have a table and can count the number of rows using var count = $("table tr").length;

Basically, I have up and down arrow controls to reorder the rows in the table. I do not want the down arrow to appear for the last row and similarly the up arrow to appear for the top row.

Is there a way to refer to specific rows in the table so that I can prevent this?

Thanks.

+3  A: 

$("table tr:first") and $("table tr:last") will return the first and last rows respectively.

Steerpike
A: 

I believe the selector itself $(...) returns an array, so you should be able to iterate through all objects in your script.

tschaible
A: 

a jQuery object is an array of all matching elements, so...

var rows = $("table tr");
var firstRow = rows[0];
var lastRow = rows[rows.length - 1];
jayrdub
Thanks.The last thing I'm still slightly confused about is combining explicit selectors with variables. eg$(lastRow "img").hide();
Dan