Thierry Lam wrote:
Let's say I have the following html tags:
<table>
<tr>
<td id="id0">HelloWorld</td>
</tr>
</table>
I was able to retrieve the HTMLTableCellElement by
document.getElementById("id0"). How do I retrieve the value HelloWorld?
It depends a bit on what you think you'll get inside the cell. If you
know that the firstChild is a text node, then:
var cell = document.getElementById("id0");
return cell.firstChild.data;
will do the trick. However, if you aren't sure of what is in the cell,
you might find it better to use the W3C DOM textContent property with
IE's equivalent, innerText. As a fallback, use innerHTML and strip out
the tags, e.g.:
function getText(el)
{
if (el.textContent) return el.textContent;
if (el.innerText) return el.innerText;
return el.innerHTML.replace(/<[^>]*>/g,'');
}
alert( getText(document.getElementById("id0")) );
--
Rob