HTML DOM Node Information

HTML DOM Node Information

The nodeName, nodeValue, and nodeType properties contain information about nodes.

Node Properties

In the HTML DOM, each node is an object.

Objects have methods and properties that can be accessed and manipulated by JavaScript.

Three important node properties are:

  • nodeName
  • nodeValue
  • nodeType

The nodeName Property

The nodeName property specifies the name of a node.

  • nodeName is read-only
  • nodeName of an element node is the same as the tag name
  • nodeName of an attribute node is the attribute name
  • nodeName of a text node is always #text
  • nodeName of the document node is always #document

Note: nodeName always contains the uppercase tag name of an HTML element.


The nodeValue Property

The nodeValue property specifies the value of a node.

  • nodeValue for element nodes is undefined
  • nodeValue for text nodes is the text itself
  • nodeValue for attribute nodes is the attribute value

Get the Value of an Element

The following example retrieves the text node value of the <p id="intro"> tag:

Example

<html>
<body>

<p id="intro">Hello World!</p>

<script type="text/javascript">
x=document.getElementById("intro");
document.write(x.firstChild.nodeValue);
</script>

</body>
</html>

Try it yourself »


The nodeType Property

The nodeType property returns the type of node. nodeType is read only.

The most important node types are:

Element typeNodeType
Element1
Attribute2
Text3
Comment8
Document9
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值