firstChild属性返回“childNodes”数组的第一个节点,如果选定的节点没有子节点,则该属性返回null
lastChild属性返回“ChildNodes”数组的最后一个子节点,如果选定的节点没有子节点,则该属性返回null
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gbk"/>
<title>访问第一个和最后一个节点</title>
</head>
<body>
<div id="con">
<p>javascript</p>
<div>jquery</div>
<h5>php</h5>
</div>
<script type="text/javascript">
var x=document.getElementById("con");
document.write(x.firstChild.nodeName+" "+x.firstChild.nodeValue+" "+x.firstChild.nodeType+"<br />");
document.write(x.lastChild.nodeName+" "+x.lastChild.nodeValue+" "+x.lastChild.nodeType);
</script>
</body>
</html>