Movatterモバイル変換


[0]ホーム

URL:


  1. 개발자를 위한 웹 기술
  2. Web API
  3. Document
  4. Document.createTreeWalker()

This page was translated from English by the community.Learn more and join the MDN Web Docs community.

View in EnglishAlways switch to English

Document.createTreeWalker()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.

Document.createTreeWalker() 메소드는 새로운TreeWalker 객체를 반환합니다.

구문

js
document.createTreeWalker(root, whatToShow[, filter[, entityReferenceExpansion]]);

매개변수

root

TreeWalker 순회의 루트Node이다. 이것은 보통 이 문서 소유의 한 엘리먼트이다.

whatToShowOptional

NodeFilter의 상수 프라퍼티들을 조합하여 만든 비트마스크를 나타내는 선택적인unsigned long 이다. 이것은 특정 유형의 노드를 필터링하는 편리한 방법이다. 기본값은SHOW_ALL 상수를 나타내는0xFFFFFFFF이다.

상수숫자 값설명
NodeFilter.SHOW_ALL-1 (unsigned long의 최대 값)Shows all nodes.
NodeFilter.SHOW_ATTRIBUTE지원이 중단되었습니다2Shows attributeAttr nodes. This is meaningful only when creating aTreeWalker with anAttr node as its root; in this case, it means that the attribute node will appear in the first position of the iteration or traversal. Since attributes are never children of other nodes, they do not appear when traversing over the document tree.
NodeFilter.SHOW_CDATA_SECTION지원이 중단되었습니다8ShowsCDATASection nodes.
NodeFilter.SHOW_COMMENT128ShowsComment nodes.
NodeFilter.SHOW_DOCUMENT256ShowsDocument nodes.
NodeFilter.SHOW_DOCUMENT_FRAGMENT1024ShowsDocumentFragment nodes.
NodeFilter.SHOW_DOCUMENT_TYPE512ShowsDocumentType nodes.
NodeFilter.SHOW_ELEMENT1ShowsElement nodes.
NodeFilter.SHOW_ENTITY지원이 중단되었습니다32ShowsEntity nodes. This is meaningful only when creating aTreeWalker with anEntity node as its root; in this case, it means that theEntity node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.
NodeFilter.SHOW_ENTITY_REFERENCE지원이 중단되었습니다16ShowsEntityReference nodes.
NodeFilter.SHOW_NOTATION지원이 중단되었습니다2048ShowsNotation nodes. This is meaningful only when creating aTreeWalker with aNotation node as its root; in this case, it means that theNotation node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.
NodeFilter.SHOW_PROCESSING_INSTRUCTION64ShowsProcessingInstruction nodes.
NodeFilter.SHOW_TEXT4ShowsText nodes.
filterOptional

선택적인NodeFilter이다.TreeWalkerwhatToShow 체크를 통과한 노드의 승인여부를 판단하기 위해 호출하는acceptNode 메소드를 가진 객체이다.

entityReferenceExpansionOptional지원이 중단되었습니다

EntityReference를 버릴 때 그 전체 하위 트리를 같이 버려야하는지를 나타내는Boolean 플래그이다.

반환 값

새로운TreeWalker 객체.

예제

다음 예제는 body의 모든 노드들을 순회하고, 노드의 집합을 엘리먼트로 줄이고, 단순히 각 노드를 승인하고 (대신acceptNode() 메소드에서 그 집합을 줄일 수도 있다), 노드들(지금은 모두 엘리먼트지만)을 전진하기 위해 생성된 트리 워커 반복자를 이용하여 배열에 푸시한다.

js
var treeWalker = document.createTreeWalker(  document.body,  NodeFilter.SHOW_ELEMENT,  {    acceptNode: function (node) {      return NodeFilter.FILTER_ACCEPT;    },  },  false,);var nodeList = [];while (treeWalker.nextNode()) nodeList.push(treeWalker.currentNode);

명세

Specification
DOM
# dom-document-createtreewalker

브라우저 호환성

참고

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp