JQuery, select first row of table

Can't you use the first selector ?

something like: tr:first


This is a better solution, using:

$("table tr:first-child").has('img')


Ok so if an image in a table is clicked you want the data of the first row of the table this image is in.

//image click stuff here {
$(this). // our image
closest('table'). // Go upwards through our parents untill we hit the table
children('tr:first'); // Select the first row we find

var $row = $(this).closest('table').children('tr:first');

parent() will only get the direct parent, closest should do what we want here. From jQuery docs: Get the first ancestor element that matches the selector, beginning at the current element and progressing up through the DOM tree.


late in the game , but this worked for me:

$("#container>table>tbody>tr:first").trigger('click');