Solved

why this script  does not work ?

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now