![]() |
mail us
|
mail this page products | company | support | downloads | isp services | contact us |
W3C Core Reference. Part of the Document Interface.
Creates a single instance of a new text node. Text nodes return '3' (TEXT_NODE) to the nodeType and '#text' to nodeName attributes. The text contents are read and written using the nodeValue attribute.
node = document.createTextNode(textstring)
| Param | Description |
| textstring | the required text e.g. 'added text' |
// create a new paragraph
newpara = document.createElement("p");
// now some text
sometext = document.createTextNode("what a way to spend a life");
// stick them onto an existing object
existingobject = document.getElementById("one");
existingobject.appendChild(newpara);
existingobject.appendChild(sometext);
We create an empty paragraph newpara element and some text sometext and appends them (in the order shown) onto the existingobject which has id="one".
createTextNode creates a single instance of the text which can only be used once.
// this code will NOT give desired results
// create a text node
// note: snippet assumes obj1 and obj2 are known to be para nodes
sometext = document.createTextNode("what a way to spend a life");
// stick same text onto existing objects - DOES NOT WORK
obj1 = document.getElementById("one");
obj2 = document.getElementById("two");
obj1.appendChild(sometext);
obj2.appendChild(sometext);
// this code WILL give desired results
// note: snippet assumes obj1 and obj2 are known to be para nodes
// now create text
sometext = document.createTextNode("what a way to spend a life");
// add text onto existing objects
obj1 = document.getElementById("one");
obj2 = document.getElementById("two");
// add first instance to obj1
obj1.appendChild(sometext);
// create a new instance an add to obj2
sometext = document.createTextNode("what a way to spend a life");
obj2.appendChild(sametext);
Problems, comments, suggestions, corrections (including broken links) or something to add? Please take the time from a busy life to 'mail us' (at top of screen), the webmaster (below) or info-support at zytrax. You will have a warm inner glow for the rest of the day.
tech home
audio stuff
web stuff
dom stuff
css stuff
language stuff
regex stuff
rfc stuff
protocol stuff
cable stuff
lan wiring
rs232 wiring
howto stuff
survival stuff
wireless stuff
ascii codes
data rate stuff
telephony stuff
mechanical stuff
pc stuff
electronic stuff
tech links
open guides
RSS Feed
If you are happy it's OK - but your browser is giving a less than optimal experience on our site. You could, at no charge, upgrade to a W3C STANDARDS COMPLIANT browser such as Mozilla
W3C HTML 4.01
HTML5 (WHATWG)
HTML4 vs HTML5
HTML5 Reference
W3C Page Validator
W3C DOCTYPE
W3C DOM
W3C DOM Events
Gecko DOM
MSIE DOM
usability.gov
W3C -WAI
Web Style Guide
Michael L Bernard
WebAim.org
Peter-Paul Koch
A List Apart
Eric Meyer on CSS
glish.com
DOCTYPE definitions
Our DOM Pages
DOM User Guide
DOM Explorer
DOM Navigation
CSS Short Cuts
CSS Techniques
CSS overview
Oh Really!
webmasterbase.com
Brainjar Menubar
Our Lite JS Menus
Our CSS Menus
Tigra Menus
|
Copyright © 1994 - 2010 ZyTrax, Inc. All rights reserved. Legal and Privacy |
site by zytrax![]() |
web-master at zytrax Page modified: May 15 2009. |