Need help using substringData()

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I can't seem to get subStringData() to work.  Can someone tell me what
I'm doing wrong and how to fix it?

Sample minimal code below.  In case it's not obvious, foo() is meant
to be a generic function, capable of accepting any element with an id
that starts with the word "column", and followed by a number.  So,
"column1", "column13", etc.  The goal is to strip off the initial word
"column" and so be left with just the number as the resultant

For the record, I've spent many hours looking over the DOM model,
searching for examples, trying various things, etc.  I still don't see
what I'm doing wrong.

Thank you


function foo(elmnt)
var txt;
var tbl;

// length of the string "column" is 6

// This one works
txt="<BR><h3>" + + " length=" + + "</h3>";

// So why doesn't this one?,end);



<td id="column1" onMouseOver="foo(this)" ><a href="#" >Text1</a></td>
<td id="column2" onMouseOver="foo(this)" ><a href="#" >Text2</a></td>


Re: Need help using substringData()

I think I figured it out.  subStringData() operates on text nodes.
The element I'm using isn't a text node, even though I want to operate
on what is still text - the id.

I found a solution.  Simply turn this non-text node string, into a
text node, and then operate on that.;
txt = document.createTextNode(str);
output = txt.substringData(6,1);

Gives me essentially what I need.  I don't like that I have to do this
in a roundabout way, but it's relatively simple and fairly painless
Seems to work.

Quoted text here. Click to load it

Re: Need help using substringData()

Quoted text here. Click to load it

function foo(elmnt)

Site Timeline