Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count number of columns in a table row

I have a table similar to:

<table id="table1"> <tr>   <td><input type="text" value="" /></td>   <td><input type="text" value="" /></td>   <td><input type="text" value="" /></td>   <td><input type="text" value="" /></td> </tr> <tr>   <td><input type="text" value="" /></td>   <td><input type="text" value="" /></td>   <td><input type="text" value="" /></td>   <td><input type="text" value="" /></td> </tr> <table> 

I want to count the number of td element in a row. I am trying:

document.getElementById('').cells.length; document.getElementById('').length; document.getElementById('').getElementsByTagName('td').length; 

It did not show actual result.

like image 955
Muhammad Imran Tariq Avatar asked Apr 06 '12 12:04

Muhammad Imran Tariq


People also ask

How do I find the number of columns in a row?

If you need a quick way to count rows that contain data, select all the cells in the first column of that data (it may not be column A). Just click the column header. The status bar, in the lower-right corner of your Excel window, will tell you the row count.

How do I count the number of columns in a table?

mysql> SELECT COUNT(*) AS NUMBEROFCOLUMNS FROM INFORMATION_SCHEMA. COLUMNS -> WHERE table_schema = 'business' AND table_name = 'NumberOfColumns'; The output displays the number of columns.


1 Answers

document.getElementById('table1').rows[0].cells.length 

cells is not a property of a table, rows are. Cells is a property of a row though

like image 142
Martin Hansen Avatar answered Oct 09 '22 07:10

Martin Hansen