peterHasemann peterHasemann - 1 year ago 97
jQuery Question

Focus the first element on a new row

When i add a new row to a Html table, i want to focus the first Cell of this row.

My current code is

$('table td').first().focus(); // focus on the first cell of the row

but this selects the first cell of the entire table. What is needed to get the first cell of the added row?

Answer Source

That's saying, "Find the first td in table."

You want, "Find the first td in the last tr in table."

$('table tr').last().find('td').first().focus();

That's assuming the last tr is the row that was just added.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download