Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Need help using substringData()
June 29, 2007, 1:59 am
rate this thread
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.
// length of the string "column" is 6
// This one works
txt="<BR><h3>" + elmnt.id + " length=" + elmnt.id.length + "</h3>";
// So why doesn't this one?
<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.
- » How to make fieldset auto size to its inner content?
- — Next thread in » HTML Authoring Forum