473,473 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Retrieving a table cell object

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?

Thierry

Sep 25 '06 #1
2 21831
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?
HTMLTableCellElement.firstChild.nodeValue.

The firstChild is a text node.

--
Ian Collins.
Sep 25 '06 #2
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

Sep 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim Madsen | last post by:
I am trying to learn JavaScript--(complete newbie--and don't know C or C++). I've been reading "The Book of JavaScript" by Thau. I don't see anything about table properties in the book. (I...
6
by: Anon | last post by:
I have a table with a cell. The cell's ID is created using a unique name that is held in m_UniqueCellName and the cell is created like so... document.write( "<TD ID="' + m_UniqueCellName +...
2
by: Michael Satterwhite | last post by:
I need to be able to dynamically change the contents of a table cell (e.g. the text between <td> and </td>. I've been searching the web, but haven't found the solution to this one. I know the...
1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
2
by: GV | last post by:
Hi all, I created 2 label controls and add them to a table cell the first one is fine left justified but i want to right justify the 2nd label control to the right of the cell? How to you...
1
by: Bart Lateur | last post by:
I'm trying to put a utton at the bottom (right) of a TD cell, irrespective of what else is in there. Usually, with other HTML block elements, we're told to use position: relative on the...
4
by: ma | last post by:
Hello, I want to inject a piece of JavaScript inside a table cell. How can I do this? The table is statically created on master page.
2
by: Vasu | last post by:
Hi! Could anybody help me guide how to write something in between <td></ tdtags. When I try to write through document.write, it wipes the whole table and writes on to a blank document, but when...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.