Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get first input from a Container on each Table row

Tags:

html

jquery

I have this table:

<table id="fieldContainer">
<tr><td><input id="input1"></td><td><input id="input2"></td></tr>
<tr><td><input id="input3"></td><td><input id="input4"></td></tr>
<tr><td><input id="input5"></td><td><input id="input6"></td></tr>
</table>

How do I get only first input on each tr?

current code:

$('#fieldContainer :input').each(function(){
  console.log($(this).val());
});

wanted input: input1,input3,input5

like image 494
Wildan Muhlis Avatar asked Feb 21 '26 07:02

Wildan Muhlis


2 Answers

You can do:

$('#fieldContainer tr td:first-child input').each(function(){
     alert($(this).val());
});

Check this fiddle

like image 86
karthikr Avatar answered Feb 22 '26 19:02

karthikr


You can use :first pseudo-selector:

$('#fieldContainer tr input:first')
like image 45
Blender Avatar answered Feb 22 '26 21:02

Blender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!