get a table cell value

Y

yukatan

let's say this is a html table, how can i get the string value contained in
the X cell ?
 
L

Lasse Reichstein Nielsen

yukatan said:
let's say this is a html table, how can i get the string value contained in
the X cell ?

Don't draw using a proportional font. There is little chance that the
receiver uses the same proportional font. If you draw using a fixed
width font, then at least all other fixed width fonts will give a
correct drawing. My newsreader uses a fixed with font, as does a lot
of others.


To get the cell, assuming that the id of the table is "tableId":

var table = document.getElementById("tableId");
var row = table.rows[2];
var cell = row.cells[0];

The hard part is getting the content of the cell. If it is plain,
unstyled text, then you can probably use:

var content = cell.firstChild.nodeValue;

Otherwise you must either use proprietary methods like cell.innerText
that doesn't work in all modern browsers, or you must gather the text
recursively. Since you just say "string value", I assume it is plain,
unstyled text.

/L
 
L

Lasse Reichstein Nielsen

Whether its styled text or not, why not innerHTML if you get out of
the W3C and into proprietary? At least allows it to work somewhere
besides IE :(

Yes, but that doesn't get the text of styled content, but the HTML code.
You will have to remove the tags to get just the text.

It all depends on what the original poster wants, which wasn't clear.

/L
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top