Solved

why this script  does not work ?

Posted on 2011-09-19
4
319 Views
Last Modified: 2012-05-12
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 ?
0
Comment
Question by:cofactor
  • 2
4 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 50 total points
ID: 36560700
So, you want to update the name of input with name id0 in second last row?

$('#myTable tr:last-child').prev().find(' td input[name="id0"]').attr('name', 'id1');
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36560775
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');
0
 

Author Comment

by:cofactor
ID: 36560811
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
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 150 total points
ID: 36560852
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question