instanceof java
Posts: 576
Nickname: instanceof
Registered: Jan, 2015
instanceof java is a java related one.
Get table cell data using JavaScript
Posted: May 2, 2016 6:41 AM
This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: Get table cell data using JavaScript
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java
Advertisement
How to get table row data in javascript: When we are working with HTML tables we will get a scenario like to get whole table rows data, or table td values , table cell value in JavaScript. For that we need to read the table by using JavaScript. lets see example on get table cell data using java script. Before that lets see how to read the data of table using JavaScript To find number of rows of a table by using table id in JavaScript.
var numberOfrows=document.getElementById("tableData").rows.length; Get number of cells or number of tds inside each tr (table row) var numberoftds = document.getElementById("tableData").rows[0].cells.length; JavaScript get table row values get table td data var numberoftds = document.getElementById("tableData").rows[0].cells.item(0).innerHTML; Example on get table each row data using javascript: <script type="text/javascript"> function checkFun() { var n1 = document.getElementById("tableData").rows.length; var i=0,j=0; var str=""; for(i=0; i<n1;i++){ var n2 = document.getElementById("tableData").rows[i].cells.length; for(j=0; j<n2;j++){ var x=document.getElementById("tableData").rows[i].cells.item(j).innerHTML;\ str=str+x+":"; } str=str+"#"; } document.getElementById("tablecontent").innerHTML=str; } </script> <body onload="checkFun()"> <table id="tableData" border="1"> <tr> <td >37</td> <td >46</td> <td >3</td> <td >64</td> </tr> <tr> <td >10</td> <td >4</td> <td >7</td> <td >21</td> </tr> </table> <p id="tablecontent" ></p> </body>
Here in this example on page loading we called the JavaScript function For that used body onload="func()" . Practice this example in your System.
Read: Get table cell data using JavaScript