Gets or sets the value of a node.
Syntax
| JavaScript | |
|---|
Property values
Type: Variant
the node value or null.
Standards information
- Document Object Model (DOM) Level 1 Specification, Section 1.2
Remarks
If the object is a TextNode object, the nodeValue property returns a string that represents the text that the node contains.
You cannot use expressions to change the nodeValue of a TextNode object.
If the object is an attribute object retrieved from the attributes collection, the nodeValue property returns the value of the attribute if it has been specified, or null otherwise.
If the object is an element, the nodeValue returns null. Use the nodeName property to determine the element name.
Examples
The following code example alters the text of the specified list item by setting the nodeValue property of the text node that is contained by that list item.
<SCRIPT>
function fnChangeValue(oList, iItem, sValue){
// only perform the operation on lists
if (oList.nodeName != "UL" && oList.nodeName != "OL")
return false;
// only perform the operation if the specified index is
// within the acceptable range of available list items
if (iItem > oList.childNodes.length -1)
return false;
// get a reference to the specified list item
var oLI = oList.childNodes(i);
if (!oLI)
return false;
// get a reference to the text node contained by the list item
var oText = oLI.childNodes(0);
// ensure that the node is a text node
if (oText.nodeType != 3)
return false;
oText.nodeValue = sValue;
return true;
}
</SCRIPT>
<UL ID="oList" onclick="fnChangeValue(this, 0, 'New Node value')">
<LI>Old Node Value
</UL>
See also
- a
- abbr
- address
- area
- attribute
- b
- base
- bdo
- blockQuote
- body
- br
- button
- caption
- cite
- code
- col
- colGroup
- comment
- dd
- del
- div
- dl
- documentType
- dt
- em
- embed
- fieldSet
- form
- head
- hn
- hr
- html
- i
- iframe
- img
- input type=button
- input type=checkbox
- input type=file
- input type=hidden
- input type=image
- input type=password
- input type=radio
- input type=reset
- input type=submit
- input type=text
- ins
- kbd
- label
- legend
- li
- link
- map
- object
- ol
- option
- p
- pre
- ProcessingInstruction
- q
- s
- samp
- script
- select
- small
- span
- strong
- sub
- sup
- table
- tBody
- td
- textArea
- TextNode
- tFoot
- th
- tHead
- title
- tr
- u
- ul
- var
- Reference
- value
- Conceptual
- About the W3C Document Object Model
Build date: 11/28/2012