473,663 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting text simple?

> <URL:http://developer.mozil la.org/en/docs/DOM:element.tex tContent>

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 3544


one man army wrote:
<URL:http://developer.mozil la.org/en/docs/DOM:element.tex tContent>

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.textCon tent 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.hasChi ldNodes()) {
element.removeC hild(element.la stChild);
}
var doc = element.ownerDo cument || document;
element.appendC hild(doc.create TextNode(text)) ;
}

setTextContent( someElementObje ct, '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.getEle mentById('test' ).innerHTML = 'Some text'.
Simple.

Nov 23 '05 #3

one man army wrote:
<URL:http://developer.mozil la.org/en/docs/DOM:element.tex tContent>


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 "textConten t" property is not supported by your test browsers,
then effectively by setting myDiv.textConte nt="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(my Div.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.getEle mentById('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************ ***********@new sread2.arcor-online.net>,
Martin Honnen <ma*******@yaho o.de> wrote:
one man army wrote:
<URL:http://developer.mozil la.org/en/docs/DOM:element.tex tContent>

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.textCon tent 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.hasChi ldNodes()) {
element.removeC hild(element.la stChild);
}
var doc = element.ownerDo cument || document;
element.appendC hild(doc.create TextNode(text)) ;
}

setTextContent( someElementObje ct, '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.new s.prodigy.com>,
one man army <ne****@screenl ightDOT.com> wrote:
In article <43************ ***********@new sread2.arcor-online.net>,
Martin Honnen <ma*******@yaho o.de> wrote:
one man army wrote:
><URL:http://developer.mozil la.org/en/docs/DOM:element.tex tContent>
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.textCon tent 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.hasChi ldNodes()) {
element.removeC hild(element.la stChild);
}
var doc = element.ownerDo cument || document;
element.appendC hild(doc.create TextNode(text)) ;
}

setTextContent( someElementObje ct, '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
3218
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, but it adds it below the descenders. So the actual space between lines is larger than I specified. Jacob
6
6974
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
1198
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
1760
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 test web service... My Web service code is: Imports System.Web.Services
3
2302
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 and an ok button. Here's the problem: On condition A, I want input focus to go to a textbox on the panel when the form loads. On condition B, I want the input focus to go to the textbox that's on the form when the form loads. Seems pretty...
1
6476
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" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
4
6563
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 be a simple setting on the LinkLabel.Cursor property, right? Not so simple. I set the property, but still got the default 'hand' cursor. To debug, I added the following event handler to my LinkLabel control: private void...
6
7935
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 codebehind, do I need any Doctype or html tags in the page ? Thanks CS
7
3576
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 Me.cboLocation.Text = ""
0
8435
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.