Solved

why this script  does not work ?

Posted on 2011-09-19
4
321 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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…

749 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