getNextElement(node)
function:
function getNextElement(node){
if(node.nodeType==1){
return node;
}
if(node.nextSibling){
return getNextElement(node.nextSibling);
}
return null;
}
实例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
window.onload=function(){
function getNextElement(node){
if(node.nodeType==1){
return node;
}
if(node.nextSibling){
return getNextElement(node.nextSibling);
}
return null;
}
var para=document.getElementById("example");
var nownode=getNextElement(para.nextSibling);//注意传的参数是下一个节点
alert(nownode.innerText);
}
</script>
</head>
<body>
<p id="example">
sea
<span>an example of a paragraph</span>
</p>
hello world
<p>east</p>
</body>
</html>

浙公网安备 33010602011771号