By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,458 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

setting text simple?

P: n/a
> <URL:http://developer.mozilla.org/en/docs/DOM:element.textContent>

I tried setting the textContent on a trivial DIV text element.
Querying the result with window.alert() shows that it worked. Yet the
page does not change.

Is there a clean way to update the text on the screen? d.write()
d.close() causes a complete page redraw. In an application, we used to
InvalRect() the affected area, or swap an offscreen buffer. ugly white
flashing NOT!
Nov 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a


one man army wrote:
<URL:http://developer.mozilla.org/en/docs/DOM:element.textContent>

I tried setting the textContent on a trivial DIV text element.
Querying the result with window.alert() shows that it worked. Yet the
page does not change.


Which browser have you tried with? Only newer Mozilla versions and I
think Opera 9 preview support element.textContent as that is a DOM Level
3 Core property and so far support for DOM Level 3 Core has not been a
major goal for browser DOM implementors.
With pure DOM Level 2 (or 1 too) you can always do
function setTextContent (element, text) {
while (element.hasChildNodes()) {
element.removeChild(element.lastChild);
}
var doc = element.ownerDocument || document;
element.appendChild(doc.createTextNode(text));
}

setTextContent(someElementObject, 'Kibology for all.');

Some browsers like IE or Opera also implement a property named innerText
in the HTML DOM which is very much the same as textContent.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 23 '05 #2

P: n/a
Use innerHTML. So, if the id proerty of you div is 'test', do the
following: document.getElementById('test').innerHTML = 'Some text'.
Simple.

Nov 23 '05 #3

P: n/a

one man army wrote:
<URL:http://developer.mozilla.org/en/docs/DOM:element.textContent>


I tried setting the textContent on a trivial DIV text element.
Querying the result with window.alert() shows that it worked. Yet the
page does not change.

[snip]

If the "textContent" property is not supported by your test browsers,
then effectively by setting myDiv.textContent="Hello"; I would guess
that you will have created a DIV "expando" property on the DIV object
(i.e. a custom attribute), hence why it appears with
window.alert(myDiv.textContent).

Julian

Nov 23 '05 #4

P: n/a
Joel Byrd wrote:
Use innerHTML. So, if the id proerty of you div is 'test', do the
following: document.getElementById('test').innerHTML = 'Some text'.
Simple.


and error-prone as it combines features of different DOMs without testing.
Why am I not surprised?
PointedEars
Nov 23 '05 #5

P: n/a
In article <43***********************@newsread2.arcor-online.net>,
Martin Honnen <ma*******@yahoo.de> wrote:
one man army wrote:
<URL:http://developer.mozilla.org/en/docs/DOM:element.textContent>

I tried setting the textContent on a trivial DIV text element.
Querying the result with window.alert() shows that it worked. Yet the
page does not change.


Which browser have you tried with? Only newer Mozilla versions and I
think Opera 9 preview support element.textContent as that is a DOM Level
3 Core property and so far support for DOM Level 3 Core has not been a
major goal for browser DOM implementors.
With pure DOM Level 2 (or 1 too) you can always do
function setTextContent (element, text) {
while (element.hasChildNodes()) {
element.removeChild(element.lastChild);
}
var doc = element.ownerDocument || document;
element.appendChild(doc.createTextNode(text));
}

setTextContent(someElementObject, 'Kibology for all.');

Some browsers like IE or Opera also implement a property named innerText
in the HTML DOM which is very much the same as textContent.


I am using Mozilla/Gecko. I had no luck at all with innerHTML, but hey,
this is new to me. I could be missing something.
Your discussion of browsers and DOM levels is hard for me to follow.
The above quoted snippet looks promising - I will give it a try.

Gecko/20050511 Firefox/1.0.4
Gecko/20030624 Mozilla/5.0

thanks!
Nov 24 '05 #6

P: n/a
In article <ne**************************@newsclstr02.news.pro digy.com>,
one man army <ne****@screenlightDOT.com> wrote:
In article <43***********************@newsread2.arcor-online.net>,
Martin Honnen <ma*******@yahoo.de> wrote:
one man army wrote:
><URL:http://developer.mozilla.org/en/docs/DOM:element.textContent>
I tried setting the textContent on a trivial DIV text element.
Querying the result with window.alert() shows that it worked. Yet the
page does not change.


Which browser have you tried with? Only newer Mozilla versions and I
think Opera 9 preview support element.textContent as that is a DOM Level
3 Core property and so far support for DOM Level 3 Core has not been a
major goal for browser DOM implementors.
With pure DOM Level 2 (or 1 too) you can always do
function setTextContent (element, text) {
while (element.hasChildNodes()) {
element.removeChild(element.lastChild);
}
var doc = element.ownerDocument || document;
element.appendChild(doc.createTextNode(text));
}

setTextContent(someElementObject, 'Kibology for all.');

Some browsers like IE or Opera also implement a property named innerText
in the HTML DOM which is very much the same as textContent.


The above quoted snippet looks promising - I will give it a try.


great, this works. And I now get how the style is set for the element as
well. I am really just replacing the text part within a defined style.

Add Asynch, as off I go.

thanks
Nov 27 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.