How to scroll all form elements inside a table row using jquery?

How to get all form elements inside a table row? Each row can have many tds with each td having any number of input or selection elements.

Please, help.

+4
source share
5 answers

You should be able to do this:

$('#myTableRow').find('input, select, textarea').each(function() { }); 
+7
source

Try it -

 $("table tr :input").each(function () { //your logic here //alert(this.tagName) }) 

Working demo - http://jsfiddle.net/ipr101/qMS7P/

+2
source

I would suggest:

 $('table input, table textarea, table select').each(function() { ... }); 
0
source

For table rows, you can select all inputs similar to this:

 var myInputFields = $("#myTable tr input[type='text']"); 

This will only select the input, no matter how many levels are in the depth of the table, so you can have lines with div> s, p> s and other things wrapped around input> s.

You can use jQuery.each or just for i = 0-> myInputFields.length to scroll through all the input fields.

 myInputFields.each(function(i,v){ var v = $(v); console.debug(v.html(),v.val()); }); 

You can expand the selector for more input / text fields, etc. easy as in the answer to simoncereska.

0
source

If you want inputs on a specific line:

HTML

 <table> <tr id="the_row"> <td><input type="text" value="1"/></td> <td><input type="text" value="2"/></td> </tr> <tr> <td><input type="text" value="3"/></td> <td><input type="text" value="4"/></td> </tr> </table> 

Javascript

 $("#the_row :input").each(function () { console.log(this.value); }); 

(Note: the :input selector matches all input , select , textarea and button elements)

DEMO : http://jsfiddle.net/WuamV/

0
source

All Articles