summer
summer

Reputation: 173

Jquery selector table>row>cell>field

with this I get all input fields in a table

$( "table.form>tbody>tr>td>input" )

return:

<input id="id_form-0-id" type="hidden" value="21">
<input id="id_form-1-id"  type="text" value="31">

now I need to read a value, this code return the value of the first input field in list:

$( "table.form>tbody>tr>td>input" ).val();
"21"

I've tried:

$( "table.form>tbody>tr>td>input" )[1].val();
 Uncaught TypeError: undefined is not a function

how can I get another field value by is index position?

Upvotes: 1

Views: 309

Answers (2)

AmmarCSE
AmmarCSE

Reputation: 30597

$( "table.form>tbody>tr>td>input" )[1].val();

is giving you the native javascript DOM element.

So either do

$( "table.form>tbody>tr>td>input" )[1].value

or use jQuery :eq() as a selector like

$( "table.form>tbody>tr>td>input:eq(1)" ).val();

or .eq() as a method like

$( "table.form>tbody>tr>td>input").eq(1).val();

Upvotes: 2

Varun
Varun

Reputation: 1946

I didnt get you question fully but if you want the values of the individual text fields then try this.

$( "table.form>tbody>tr>td>input:nth-child(x)" ).val();

where x will be the element no whose value you want.And x will start from 1. So values of 1st element would be

$( "table.form>tbody>tr>td>input:nth-child(1)" ).val();

and so on...

Upvotes: 1

Related Questions