JavaScript

[DOM_Element] JS - children 속성 ★ - 자식요소노드 (IE9 이상)

children 예제

 

<button onclick="homzzang()">클릭</button>

<div id='box'>

  <h1>홈짱닷컴</h1>

  <h3>Homzzang.com</h1>

  <p>홈페이지 제작관리</p>

</div>

<p id="demo"></p>


<script>

function homzzang() {

  var box = document.getElementById('box');

  var c = box.children;

  var txt = "";

  var i;

  for (i = 0; i < c.length; i++) {

    txt = txt + c[i].tagName+ "<br>";

  }


  document.getElementById("demo").innerHTML = txt;

}

</script>

 

결과보기

결과값:

H1

H3

P

 

 

반환값 차이:

IE9 미만 : 요소노드 + 주석노드
IE9 이상 : 요소노드만.

방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
DOM_Attribute JS - nodemap.item() 메서드 -
DOM_Attribute JS - nodemap.length -
DOM_Attribute JS - nodemap.removeNamedItem() 메서드 -
DOM_Attribute JS - nodemap.setNamedItem() 메서드 -
DOM_Attribute JS - attr.appendChild() 메서드 - 사용금지
DOM_Attribute JS - attr.attributes - 사용금지
DOM_Attribute JS - attr.baseURI - 사용금지
DOM_Attribute JS - attr.childNodes - 사용금지
DOM_Attribute JS - attr.cloneNode() 메서드 - 사용금지
DOM_Attribute JS - attr.firstChild -
DOM_Attribute JS - attr.hasAttributes() 메서드 -
DOM_Attribute JS - attr.hasChildNodes -
DOM_Attribute JS - attr.insertBefore() 메서드 -
DOM_Attribute JS - attr.isEqualNode() 메서드 -
DOM_Attribute JS - attr.isSameNode() 메서드 -
27/89
목록
  • 채팅방
  • 필독
1. 채팅창 헤드에서 접속자 확인 2. 닉네임 클릭해 1:1 채팅 가능 3. 닉네임 클릭해 귓속말 가능 4. 닉네임 클릭해 호출하기 가능 5. 우하단 클릭해 환경 설정 가능 6. 의뢰글 작성 후 의뢰 상담 가능 7. 질문글 작성 후 질문 상담 가능 8. 채팅방에 개인정보 입력 금지 9. 채팅방에 광고 욕설 비방 금지
 홈  PC버전 로그인 일본어
웹디자인언어
서버관리언어 1
고급코딩언어
그누보드 3
제작의뢰
Q&A
커뮤니티 1
웹유틸
회원센터
홈짱 PC버전 로그인