473,387 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

setting text simple?

> <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
6 3530


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
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

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jacob Weber | last post by:
Hello. Is it possible to specify the exact space between two lines, measured from the baseline of the top line to the ascenders of the second line? I tried adding the space with padding-bottom,...
6
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
2
by: Tina | last post by:
As I design my page, I want to make sure it looks good if the Text Size is set to largest in the I.E browser. How can I set my design view so object appear that way as I build my page? Thanks, T
2
by: Greg | last post by:
Please note: I have cross posted this from Newsgroup: microsoft.public.dotnet.framework.aspnet.webservices with a few minor changes... I am having a simple problem setting up the security on my...
3
by: Mike Eaton | last post by:
Hi there, I've got what I hope is a simple problem to solve... Here's the back story: I have a windows form. On the form is a panel containing three textboxes. Also on the form is a text box...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
4
by: David Veeneman | last post by:
I'm creating a UserControl that uses a LinkLabel. For reasons that I won't bore everyone with, I don't want the LinkLable to show the default hand cursor when the mouse enters the control. Should...
6
by: WT | last post by:
Hello, I am searching for a way to generate automatically from codebehind the <!Doctype....for asp.net pages using .net 3.5 c# and vs2008. Subidiary question: if I do a server transfert in my...
7
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.