Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

why this script  does not work ?

Posted on 2011-09-19
4
Medium Priority
?
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 200 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 600 total points
ID: 36560852
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

661 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