nodeName, nodeType, nodeValue, firstChild, lastChild, previousSibling, nextSibling 속성 예제


  • 항목 1
  • 항목 2
  • 항목 3
  • 항목 4
SPAN1 내용 SPAN2 내용

<DIV id=divObj style="border:solid 1 blue;padding:5">
<IMG id="img1" src="../../../gif/rfproperty.gif"><BR id=br1>
<UL id=ulObj>
<LI id=li1>항목 1
<LI id=li2>항목 2
<LI id=li3>항목 3
<LI id=li4>항목 4
</UL>
<DIV id=div1 style="border:solid 1 gray"><SPAN id=span1>SPAN1 내용</SPAN> <SPAN id=span2>SPAN2 내용</SPAN></DIV>
<IMG id="img2" src="../../../gif/rfexample.gif"><BR id=br2>
</DIV>

<SCRIPT>
objCol=divObj.all;
str='divObj.all.length=objCol.length='+objCol.length+'<BR>';
str+='<TABLE border=1>';
str+='<COL style=white-space:nowrap>';
str+='<COLGROUP style=text-align:center><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP>';
str+='<TR class=property style=font-size:80%><TD> </TD><TD>id</TD><TD>nodeName</TD><TD>nodeType</TD>';
str+='<TD>nodeValue</TD><TD>firstChild.id</TD><TD>lastChild.id</TD>';
str+='<TD>previousSibling.id</TD><TD>nextSibling.id</TD></TR>';
for (i=0;i< objCol.length;i++){
  str+='<TR><TD>objCol['+i+']</TD>';
  str+='<TD>'+objCol[i].id+'</TD>';
  str+='<TD>'+objCol[i].nodeName+'</TD>';
  str+='<TD>'+objCol[i].nodeType;
  if (objCol[i].nodeType==1) str+='<SMALL>(element)</SMALL>';
  str+='</TD>';
  str+='<TD>'+objCol[i].nodeValue+'</TD>';

  if ((objCol[i].firstChild)&&(objCol[i].firstChild.id!=undefined)) str+='<TD>'+objCol[i].firstChild.id+'</TD>';
  else str+='<TD>-</TD>';
  if ((objCol[i].lastChild)&&(objCol[i].lastChild.id!=undefined)) str+='<TD>'+objCol[i].lastChild.id+'</TD>';
  else str+='<TD>-</TD>';
  if ((objCol[i].previousSibling)&&(objCol[i].previousSibling.id!=undefined)) str+='<TD>'+objCol[i].previousSibling.id+'</TD>';
  else str+='<TD>-</TD>';
  if ((objCol[i].nextSibling)&&(objCol[i].nextSibling.id!=undefined)) str+='<TD>'+objCol[i].nextSibling.id+'</TD>';
  else str+='<TD>-</TD>';
  str+='</TR>';
}
str+='</TABLE><BR>';
str+='ulObj.previousSibling.nodeName='+ulObj.previousSibling.nodeName+'<BR>';
str+='ulObj.nextSibling.nodeName='+ulObj.nextSibling.nodeName+'<BR>';
str+='ulObj.firstChild.nodeName='+ulObj.firstChild.nodeName+'<BR>';
str+='ulObj.lastChild.innerText='+ulObj.lastChild.innerText+'<BR>';
str+='ulObj.firstChild.nextSibling.innerText='+ulObj.firstChild.nextSibling.innerText+'<BR>';
str+='ulObj.childNodes(0).nextSibling.innerText='+ulObj.childNodes(0).nextSibling.innerText+'<BR>';
str+='divObj.firstChild.src='+divObj.firstChild.src+'<BR>';
document.write(str)
</SCRIPT>