nodeValue property
Sets or returns the value of the current node.
The attribute.nodeValue, document.nodeValue and the TextNode.nodeValue properties are read/write, all others are read-only.
Syntax:
You can find the related objects in the Supported by objects section below.
Possible values:
The value depends on the type of the node.
The following table contains the possible values:
In the case of Attribute nodes. In Internet Explorer, the type of the value can also be Boolean (e.g. checked) and number (e.g. colSpan) and the value is always null for certain event attributes (e.g. onload), regardless of whether it is specified. | |||||||
In the case of Text, CDATASection and Comment nodes. | |||||||
In the case of ProcessingInstruction nodes. | |||||||
In the case of Element, Document, DocumentFragment, DocumentType, EntityReference, Entity and Notation nodes. |
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the nodeValue property:
|
||||
<head> <script type="text/javascript"> function GetNodeInfo () { var div = document.getElementById ("myDiv"); var commentNode = div.firstChild; var message = ""; message += "The name of the node: " + commentNode.nodeName + "\n"; message += "The type of the node: " + commentNode.nodeType + "\n"; message += "The value of the node: " + commentNode.nodeValue; alert (message); } </script> </head> <body> <div id="myDiv"><!-- this text is not rendered --></div> <button onclick="GetNodeInfo ()">Get node info!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
attribute, CommentNode, doctype, document, DocumentFragment, TextNode, XMLDocument
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
Related pages:
External links:
User Contributed Comments