Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Paul Clapham
Sheriffs:
paul wheaton
Tim Cooke
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Piet Souris
Bartenders:
Mike London
Forum:
HTML Pages with CSS and JavaScript
Get Rows from a Table
kavin clain
Ranch Hand
Posts: 68
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I want to get all rows (<tr> elements) of a given Table.
I tried the below steps but the results are different in different browsers.
Is there any correct way to do it?
Note: There are several other table elements in the same html page. html: <table id="prsnl"> <tr> <td>name</td> </tr> <tr> <td>dob</td> </tr> <tr> <td>Designation</td> </tr> </table> js: var theTbl = document.getElementById('prsnl'); var allRows = theTbl.childNodes; for(var i=0;i<allRows.length;i++){ alert(allRows.nodeNme); //---- here I get either 'TR' or '#text' in different browsers. }
Eswar Nec
Ranch Hand
Posts: 105
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Try this
Here you may get each row object.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> <script type="text/javascript"> function getAllRows(tableId) { var table = document.getElementById(tableId); var rows = table.getElementsByTagName("tr"); for(i = 0; i < rows.length; i++) { alert( i + " row : " + rows[i]); } } </script> </head> <body> <table id="prsnl"> <tr> <td>name</td> </tr> <tr> <td>dob</td> </tr> <tr> <td>Designation</td> </tr> </table> <input type="button" value="AllRows" onclick="getAllRows('prsnl')"/> </body> </html>
<body onload="getAllRows('prsnl')"> //.... //... </body>
Wake up! Don't let your smile be snatched away by anybody!
Regards, Eswar
kavin clain
Ranch Hand
Posts: 68
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you Eswara.
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Passing Table values to action class
Adding a row to a HTML table on-the-fly
Help me to have a sortable table in my html profile!
values undefined in arrays
Table with Scrollbar
More...