get value of TD

P

polilop

How can i get value of a td in a table?
I tried
tabl=document.getElementById("table").rows[0].innerText;

but this is only supported by iexplorer.
 
R

Randy Webb

polilop said the following on 2/20/2006 12:11 PM:
How can i get value of a td in a table?
I tried
tabl=document.getElementById("table").rows[0].innerText;

but this is only supported by iexplorer.

..nodeValue
..innerHTML

Among others.
 
P

polilop

.node Value not Supported by Mozilla
.innerHTML works fine

Thx


Randy Webb said:
polilop said the following on 2/20/2006 12:11 PM:
How can i get value of a td in a table?
I tried
tabl=document.getElementById("table").rows[0].innerText;

but this is only supported by iexplorer.

.nodeValue
.innerHTML

Among others.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/
 
M

Martin Honnen

polilop said:
.node Value not Supported by Mozilla

Randy said nodeValue not node Value. nodeValue is supported by Mozilla
as it is specified in the W3C DOM Core for any node. However for element
nodes nodeValue is by definition null which is not what you are looking
for if you use innerText in the IE DOM.
 
R

RobG

polilop said:
How can i get value of a td in a table?
I tried
tabl=document.getElementById("table").rows[0].innerText;

but this is only supported by iexplorer.

I guess you are after the text in the node with any HTML tags stripped
out. The following function uses W3C DOM 3 textContent or innerText or
recurses through the child nodes grabbing the text.

You may want to modify it to deal with other node types.


function getElText(el)
{
if (el.textContent) return el.textContent;
if (el.innerText) return el.innerText;
var x = el.childNodes;
var txt = '';
for (var i=0, len=x.length; i<len; ++i){
if (3 == x.nodeType) {
txt += x.data;
} else if (1 == x.nodeType){
txt += getElText(x);
}
}
return txt.replace(/\s+/g,' ');
}
 

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
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top