Get Table Cell Value using Javascript

G

Guest

How do I get the text from my cell e..g. <td>Test Text</td>



var elTableCells = elTableRow.getElementsByTagName("td");

alert(elTableCells[0].innerText);
 
C

Cowboy \(Gregory A. Beamer\)

The easiest way to get a particular cell is to give it an ID, of course. You
then do not have to play any games. Even if you are binding, you can do this
by adding IDs during the data binding event. You can add IDs and even add
events if a person clicks a cell. It takes slightly longer to render, but it
is easier than searching through the haystack later.

If this is not an option, you will have to go through finding the table and
then iterating through rows to find the particular cell. This tutorial shows
how to create a table, but the basic process of iterating through cells is
the same:
http://developer.mozilla.org/en/docs/Traversing_an_HTML_table_with_JavaScript_and_DOM_Interfaces
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top