mail us  |  mail this page

products  |  company  |  support  |  downloads  |  isp services  |  contact us

Tech Info - DOM-2 createTextNode

W3C Core Reference. Part of the Document Interface.

createTextNode Method

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.

Syntax

node = document.createTextNode(textstring)

Related Stuff

createElement, appendChild

Parameters

Param Description
textstring the required text e.g. 'added text'

Examples

// 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".

Notes:

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

tech home
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 Icon 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

web zytrax.com



HTML Stuff

W3C HTML 4.01
HTML5 (WHATWG)
W3C Page Validator
W3C DOCTYPE

XHTML Stuff

W3C XHTML Basic
W3C XHTML 1.1
W3C CSS1
W3C CSS2.1

DOM Stuff

W3C DOM
W3C DOM Events
Gecko DOM
MSIE DOM

Usability/Access

usability.gov
W3C -WAI
Web Style Guide
Michael L Bernard
WebAim.org

Jolly Useful

Peter-Paul Koch
A List Apart
Eric Meyer on CSS
glish.com
DOCTYPE definitions

Our Stuff

Our DOM Pages
DOM User Guide
DOM Explorer
DOM Navigation
CSS Short Cuts
CSS Techniques
CSS overview
Oh Really!

Javascript

ECMA-262

Pop-out Menus

webmasterbase.com
Brainjar Menubar
Our Lite JS Menus
Our CSS Menus
Tigra Menus

printer friendly

Print Page

SPF Record Conformant Domain Logo

Copyright © 1994 - 2008 ZyTrax, Inc.
All rights reserved. Legal and Privacy
site by zytrax
Hosted by super.net.sg
web-master at zytrax
Page modified: September 04 2007.