Element nodeType values
3754 ワード
Last udated:Febrary 27 th、2006
The term“node s”is just a fancy way of referring to all the elemens in a document,whether it's paparticularDIV,or the texcontainininininininside it.The“nodeType”propertyof the DOM isisverhelpful thererererererererererererererererererereremimimimimimimimimimimimimimimimimimimimimimitytytytythethethethethethererererererererererererererererererererererererererererererererererererererererererererereible values returned by「nodeType」:
nodeType values chart
Returned integer Node type Content
1
ELLENTNODE
2
ATTRIBUTE NODE
3
TEXTNODE
4
CDATA_SECTIONNODE
5
ENTITYUREFE RENCE NODE
6
ENTITYNODE
7
PROCESSINGuINSTRUCTION_NODE
8
COMMENT NODE
9
DOCUMENT_NODE
10
DOCUMENTタイプ
11
DOCUMENT_FRAGMENT_NODE
12`
NOTATIONNODE
Consinder the follwing HTML code:
With the above HTML block,you don't really need the"nodeType"property トテルyou the types of the three nodes you're accessing.But consider this slightly modified example:
Here I've added a blank space in front of the B element.To some browsers such as Firefox,a blank space is consided a text node(nodeType=3)just like reglar text,while in others such as IE,the note the.ext.「after the DIV element varies depending on which browser you ask,with Firefox sayng it's a text node,while IE says it's an element node(B element).Without the help of the nodetypt.eypt.eypt the
nodeName property
If the integer value returned by the“nodeType”property abstract for you,a more huoman,albeit less robust way,of returning the type of a node is using the“nodeName”property.It returns a stining a stining didicantine the name of propernation.
Returned string Indicates
同前
This is a commment node.
同前
This the document node.
element.tagName
The tagName of the element、indicating this an element at the same time.
Attri.name
The name of the atribute、indicating this an atribute node at the same time.
ヽoo.ツ
This is a text node.
For example:
nodeValue property
The.「nodeValue」property is a read/write property that refrets the current value of a node.For text nodes,the content of the node is returned,while for atribute nodes,the atribute valute valute.Nultrement fore
<script type=「text/javascript」>text/javascript"///>スクリプト>
The term“node s”is just a fancy way of referring to all the elemens in a document,whether it's paparticularDIV,or the texcontainininininininside it.The“nodeType”propertyof the DOM isisverhelpful thererererererererererererererererererereremimimimimimimimimimimimimimimimimimimimimimitytytytythethethethethethererererererererererererererererererererererererererererererererererererererererererererereible values returned by「nodeType」:
nodeType values chart
Returned integer Node type Content
1
ELLENTNODE
2
ATTRIBUTE NODE
3
TEXTNODE
4
CDATA_SECTIONNODE
5
ENTITYUREFE RENCE NODE
6
ENTITYNODE
7
PROCESSINGuINSTRUCTION_NODE
8
COMMENT NODE
9
DOCUMENT_NODE
10
DOCUMENTタイプ
11
DOCUMENT_FRAGMENT_NODE
12`
NOTATIONNODE
Consinder the follwing HTML code:
<div id="adiv"><b>Some text</b></div>
<script type="text/javascript">
alert(document.getElementById("adiv").nodeType) //DIV element. Alerts 1
alert(document.getElementById("adiv").firstChild.nodeType) //B element. Alerts 1
</script>
With the above HTML block,you don't really need the"nodeType"property トテルyou the types of the three nodes you're accessing.But consider this slightly modified example:
<div id="adiv"> <b>Some text</b></div>
<script type="text/javascript">
alert(document.getElementById("adiv").nodeType) //DIV element. Alerts 1
alert(document.getElementById("adiv").firstChild.nodeType) //Alerts 1 or 3, depending on browser.
</script>
Here I've added a blank space in front of the B element.To some browsers such as Firefox,a blank space is consided a text node(nodeType=3)just like reglar text,while in others such as IE,the note the.ext.「after the DIV element varies depending on which browser you ask,with Firefox sayng it's a text node,while IE says it's an element node(B element).Without the help of the nodetypt.eypt.eypt the
nodeName property
If the integer value returned by the“nodeType”property abstract for you,a more huoman,albeit less robust way,of returning the type of a node is using the“nodeName”property.It returns a stining a stining didicantine the name of propernation.
Returned string Indicates
同前
This is a commment node.
同前
This the document node.
element.tagName
The tagName of the element、indicating this an element at the same time.
Attri.name
The name of the atribute、indicating this an atribute node at the same time.
ヽoo.ツ
This is a text node.
For example:
if (document.getElementById("test").firstChild.nodeName=="DIV")
alert("This is a DIV")
nodeValue property
The.「nodeValue」property is a read/write property that refrets the current value of a node.For text nodes,the content of the node is returned,while for atribute nodes,the atribute valute valute.Nultrement fore
<div id="test">Old text</div>
<script type="text/javascript">
if (document.getElementById("test").firstChild.nodeName=="#text")
document.getElementById("test").firstChild.nodeValue="New text"
</script>
<script type=「text/javascript」>