Link to home
Start Free TrialLog in
Avatar of cofactor
cofactor

asked on

why this script does not work ?

I want to rename a field name using jquery .  

This field is situated at  the last but one <tr>  inside myTable.

I use the following syntax to rename field name ...but this does not work

$('#myTable tr:eq(-2) > input[name="id0"]').attr('name', 'id1');

whats wrong ? how do I correct it ?
SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
http://api.jquery.com/eq-selector/

Unlike the .eq(index) method, the :eq(index) selector does not accept a negative value for index. For example, while $('li').eq(-1) selects the last li element, $('li:eq(-1)') selects nothing.

Try this :
$('#myTable tr').eq(-2).find('input[name="id0"]').attr('name', 'id1');
Avatar of cofactor
cofactor

ASKER

That code does not find name id0 in second last row ONLY.  it searches entire table.

I want to update the name of input with name id0 in second last row only. I dont want to search other places
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial