Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

textContent not working ?

1,182 views
Skip to first unread message

fd12...@hotmail.com

unread,
May 19, 2008, 10:52:36 AM5/19/08
to
Could anyone try this ? Create a html page containing the following :

<html>
<body>
<script type="text/javascript">
function Check()
{
var t = document.getElementById('t');
alert(t.textContent);
t.textContent = 'blah';
}
</script>
<textarea name="t" id="t"></textarea>
<a href="javascript:Check();">Check</a>
</body>
</html>

Load the page in FF, click on "check", everything works as expected :
the alert box is empty then "blah" is shown in the textarea.

Then delete a character in the textarea (say, the letter "h") and
click again on "check" :
1) the alert incorrectly shows "blah" instead of "bla".
2) it then should replace the contents of the textarea with "blah",
but it doesn't.

From then on, whatever you do, including refreshing the page, it won't
work as expected. Placing the script below the textarea declaration
doesn't change a thing.

So what's wrong : my expectations, my syntax, FF's textarea/
textContent handling or FF's javascript handling ? Any workarounds ?

Thanks !

Michel

fd12...@hotmail.com

unread,
May 21, 2008, 7:06:01 AM5/21/08
to
No answer, so I reported it as a bug to Bugzilla (https://
bugzilla.mozilla.org/show_bug.cgi?id=434988).

fd12...@hotmail.com

unread,
May 21, 2008, 9:12:03 AM5/21/08
to
In case anyone is interested, here's the explanation provided by John
P. Baker (thanks to him) :
<quote>
If you view the generated source you will see why this is invalid:

Before click: ...<textarea name="t" id="t"></textarea>...
After click: ...<textarea name="t" id="t">blah</textarea>...

textContent returns the text content in the DOM - not the current
value of the
control; You probably want t.value in this case.

http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent
</quote>

Hope this helps those trying to solve the "textContent vs innerText"
problem.

Michel

> > Michel- Hide quoted text -
>
> - Show quoted text -

0 new messages