차례
  1. 3 HTML 문서의 의미, 구조, API
    1. 3.1 문서
      1. 3.1.1 DOM 내부의 문서
      2. 3.1.2 보안
      3. 3.1.3 자원 메타데이터 관리
      4. 3.1.4 DOM 트리 접근자
      5. 3.1.5 문서 생성
      6. 3.1.6 XML 문서 로딩

3 HTML 문서의 의미, 구조, API

3.1 문서

모든 XML, HTML 문서들은 HTML 사용자 에이전트에서 Document 객체로 나타납니다. [DOMCORE]

Every XML and HTML document in an HTML UA is represented by a Document object. [DOMCORE]

문서의 주소절대 URL이며, 이것은 Document가 만들어질 때 정해집니다. 문서의 현재 주소절대 URL이며, Document가 존재하는 동안 변경될 수 있습니다. 예를 들어 사용자가 문서 내의 해시를 따라 움직이거나, pushState() 메서드가 새로운 URL과 함께 호출된 경우 등입니다.

The document's address is an absolute URL that is set when the Document is created. The document's current address is an absolute URL that can change during the lifetime of the Document, for example when the user navigates to a fragment identifier on the page or when the pushState() method is called with a new URL. The document's current address must be set to the document's address when the Document is created.

대화형 사용자 에이전트는 보통 문서의 현재 주소를 인터페이스에 보여줍니다.

Interactive user agents typically expose the document's current address in their user interface.

DocumentcreateDocument() 또는 createHTMLDocument() API에 의해 생성될 때, 문서의 주소the document's address of the 스크립트의 문서의 주소와 같습니다.

When a Document is created by a script using the createDocument() or createHTMLDocument() APIs, the document's address is the same as the document's address of the script's document.

Document 객체는 생성될 때 HTML 문서라고 명시되지 않으면 XML documents 문서로 간주합니다. 문서가 XML 문서인지, 또는 HTML 문서인지는 몇 가지 API와 몇몇 셀렉터의 대소문자 구분 여부 등에 영향을 미칩니다.

Document objects are assumed to be XML documents unless they are flagged as being HTML documents when they are created. Whether a document is an HTML document or an XML document affects the behavior of certain APIs and the case-sensitivity of some selectors.

각각의 Document 객체는 reload override flag을 가지며, 이것은 기본값으로는 설정되지 않습니다. 이 플랙은 특정 상황에서 document.open(), document.write() 메서드에 의해 설정됩니다. 플랙이 설정되면, Document 객체는 또한 reload override buffer를 갖게 됩니다. 이것은 문서의 소스가 리로드되었을때 사용하는 유니코드 문자열입니다.

Each Document object has a reload override flag that is originally unset. The flag is set by the document.open() and document.write() methods in certain situations. When the flag is set, the Document also has a reload override buffer which is a Unicode string that is used as the source of the document when it is reloaded.

사용자 에이전트가 an overridden reload를 수행할 때는 다음의 순서를 지켜야 합니다.

When the user agent is to perform an overridden reload, it must act as follows:

  1. 브라우징 문맥의 현재 문서의 reload override buffer의 값을 source라고 합니다.

    Let source be the value of the browsing context's active document's reload override buffer.

  2. 그 소스가 source인 자원으로 브라우징 문맥이동합니다. 이동 알고리즘이 이러한 목적으로 Document 객체를 만들 경우 Document reload override flag을 설정하고, reload override buffersource로 설정합니다.

    Navigate the browsing context to a resource whose source is source. When the navigate algorithm creates a Document object for this purpose, set that Document's reload override flag and set its reload override buffer to source.

3.1.1 DOM 내부의 문서

모든 Document 객체(이 명세를 구현하는 모든 사용자 에이전트에서)는 바인딩 관련 메서드들이 사용 가능하도록 HTMLDocument 인터페이스 역시 구현합니다. (문서가 HTML 문서인지, 혹은 HTML 요소를 포함하고 있는가 하는 경우입니다.) Document 객체는 사용자 에이전트가 지원하는 다른 네임스페이스에 대해 문서 레벨의 인터페이스 역시 구현합니다.

All Document objects (in user agents implementing this specification) must also implement the HTMLDocument interface, available using binding-specific methods. (This is the case whether or not the document in question is an HTML document or indeed whether it contains any HTML elements at all.) Document objects must also implement the document-level interface of any other namespaces that the UA supports.

예를 들어, HTML 구현이 SVG 역시 지원한다면, Document 객체는 HTMLDocumentSVGDocument 양자를 구현합니다.

For example, if an HTML implementation also supports SVG, then the Document object implements both HTMLDocument and SVGDocument.

HTMLDocument 인터페이스가 단순히 문서 객체의 일차적 인터페이스가 아닌, 바인딩 관련 캐스팅 메서드들을 이용해서 얻어졌으므로, Document를 상속한다고 정의하지 않습니다.

Because the HTMLDocument interface is now obtained using binding-specific casting methods instead of simply being the primary interface of the document object, it is no longer defined as inheriting from Document.

[OverrideBuiltins]
interface HTMLDocument {
  // resource metadata management
  [PutForwards=href] readonly attribute Location location;
  readonly attribute DOMString URL;
           attribute DOMString domain;
  readonly attribute DOMString referrer;
           attribute DOMString cookie;
  readonly attribute DOMString lastModified;
  readonly attribute DOMString compatMode;
           attribute DOMString charset;
  readonly attribute DOMString characterSet;
  readonly attribute DOMString defaultCharset;
  readonly attribute DOMString readyState;

  // DOM tree accessors
  getter any (in DOMString name);
           attribute DOMString title;
           attribute DOMString dir;
           attribute HTMLElement body;
  readonly attribute HTMLHeadElement head;
  readonly attribute HTMLCollection images;
  readonly attribute HTMLCollection embeds;
  readonly attribute HTMLCollection plugins;
  readonly attribute HTMLCollection links;
  readonly attribute HTMLCollection forms;
  readonly attribute HTMLCollection scripts;
  NodeList getElementsByName(in DOMString elementName);
  NodeList getElementsByClassName(in DOMString classNames);

  // dynamic markup insertion
           attribute DOMString innerHTML;
  HTMLDocument open(in optional DOMString type, in optional DOMString replace);
  WindowProxy open(in DOMString url, in DOMString name, in DOMString features, in optional boolean replace);
  void close();
  void write(in DOMString... text);
  void writeln(in DOMString... text);

  // user interaction
  readonly attribute WindowProxy defaultView;
  readonly attribute Element activeElement;
  boolean hasFocus();
           attribute DOMString designMode;
  boolean execCommand(in DOMString commandId);
  boolean execCommand(in DOMString commandId, in boolean showUI);
  boolean execCommand(in DOMString commandId, in boolean showUI, in DOMString value);
  boolean queryCommandEnabled(in DOMString commandId);
  boolean queryCommandIndeterm(in DOMString commandId);
  boolean queryCommandState(in DOMString commandId);
  boolean queryCommandSupported(in DOMString commandId);
  DOMString queryCommandValue(in DOMString commandId);
  readonly attribute HTMLCollection commands;

  // event handler IDL attributes
           attribute Function onabort;
           attribute Function onblur;
           attribute Function oncanplay;
           attribute Function oncanplaythrough;
           attribute Function onchange;
           attribute Function onclick;
           attribute Function oncontextmenu;

           attribute Function oncuechange;

           attribute Function ondblclick;
           attribute Function ondrag;
           attribute Function ondragend;
           attribute Function ondragenter;
           attribute Function ondragleave;
           attribute Function ondragover;
           attribute Function ondragstart;
           attribute Function ondrop;
           attribute Function ondurationchange;
           attribute Function onemptied;
           attribute Function onended;
           attribute Function onerror;
           attribute Function onfocus;
           attribute Function onformchange;
           attribute Function onforminput;
           attribute Function oninput;
           attribute Function oninvalid;
           attribute Function onkeydown;
           attribute Function onkeypress;
           attribute Function onkeyup;
           attribute Function onload;
           attribute Function onloadeddata;
           attribute Function onloadedmetadata;
           attribute Function onloadstart;
           attribute Function onmousedown;
           attribute Function onmousemove;
           attribute Function onmouseout;
           attribute Function onmouseover;
           attribute Function onmouseup;
           attribute Function onmousewheel;
           attribute Function onpause;
           attribute Function onplay;
           attribute Function onplaying;
           attribute Function onprogress;
           attribute Function onratechange;
           attribute Function onreadystatechange;
           attribute Function onreset;
           attribute Function onscroll;
           attribute Function onseeked;
           attribute Function onseeking;
           attribute Function onselect;
           attribute Function onshow;
           attribute Function onstalled;
           attribute Function onsubmit;
           attribute Function onsuspend;
           attribute Function ontimeupdate;
           attribute Function onvolumechange;
           attribute Function onwaiting;
};
Document implements HTMLDocument;

HTMLDocument 인터페이스는 서로 이질적인 다양한 기능에 연관된 메서드와 속성을 보유하므로, 이 인터페이스의 멤버들은 다양한 섹션에서 설명될 것입니다.

Since the HTMLDocument interface holds methods and attributes related to a number of disparate features, the members of this interface are described in various different sections.

3.1.2 보안

HTMLDocument 객체의 멤버 중 어느 하나라도 Document실제 스크립트 소스같지 않은 스크립트 소스의 영향을 받는다면 사용자 에이전트는 SECURITY_ERR 예외를 반환하게 됩니다.

User agents must raise a SECURITY_ERR exception whenever any of the members of an HTMLDocument object are accessed by scripts whose effective script origin is not the same as the Document's effective script origin.

3.1.3 자원의 메타데이터 관리

document . URL

문서의 주소를 반환합니다.

Returns the document's address.

document . referrer

사용자가 이 문서로 넘어오기 전에 있었던 Document주소를 반환합니다. 그것이 차단되었거나 그러한 것이 없었다면 빈 문자열을 반환합니다.

Returns the address of the Document from which the user navigated to this one, unless it was blocked or there was no such document, in which case it returns the empty string.

링크 타입 noreferrer를 사용해서 참조자referrer를 차단할 수 있습니다.

The noreferrer link type can be used to block the referrer.

The URL attribute must return the document's address.

The referrer attribute must return either the current address of the active document of the source browsing context at the time the navigation was started (that is, the page which navigated the browsing context to the current document), with any <fragment> component removed; or the empty string if there is no such originating page, or if the UA has been configured not to report referrers in this case, or if the navigation was initiated for a hyperlink with a noreferrer keyword.

HTTP의 경우, IDL 속성 referrer는 현재 페이지를 받아올 때 보내어진 Referer(sic) 헤더와 같을 것입니다.

In the case of HTTP, the referrer IDL attribute will match the Referer (sic) header that was sent when fetching the current page.

암호화된 프로토콜에서 그렇지 않은 프로토콜로 넘어왔을 경우(예를 들어, https: 에서 http:로 넘어온 경우), 일반적으로 사용자 에이전트들은 referrer를 반환하지 않습니다.

Typically user agents are configured to not report referrers in the case where the referrer uses an encrypted protocol and the current page does not (e.g. when navigating from an https: page to an http: page).


document . cookie [ = value ]

Document에 적용되는 HTTP 쿠키들을 반환합니다. 쿠키가 없거나 이 자원에 적용될 수 없으면 빈 문자열을 반환합니다.

Returns the HTTP cookies that apply to the Document. If there are no cookies or cookies can't be applied to this resource, the empty string will be returned.

요소의 HTTP 쿠키 집합에 새로운 쿠키를 더하기 위해 설정할 수 있습니다.

Can be set, to add a new cookie to the element's set of HTTP cookies.

내용이 고유 소스 정책으로 샌드박스되었거나(sandbox 속성을 갖는 iframe) 자원이 text/html-sandboxed로 레이블링 되었다면 이 메서드를 사용할 때 SECURITY_ERR 예외를 반환합니다.

If the contents are sandboxed into a unique origin (in an iframe with the sandbox attribute) or the resource was labeled as text/html-sandboxed, a SECURITY_ERR exception will be thrown on getting and setting.

The cookie attribute represents the cookies of the resource from which the Document was created.

A Document object that falls into one of the following conditions is a cookie-free Document object:

On getting, if the document is a cookie-free Document object, then the user agent must return the empty string. Otherwise, if the Document's origin is not a scheme/host/port tuple, the user agent must raise a SECURITY_ERR exception. Otherwise, the user agent must first obtain the storage mutex and then return the cookie-string for the document's address for a "non-HTTP" API, decoded as UTF-8, with error handling. [COOKIES]

On setting, if the document is a cookie-free Document object, then the user agent must do nothing. Otherwise, if the Document's origin is not a scheme/host/port tuple, the user agent must raise a SECURITY_ERR exception. Otherwise, the user agent must obtain the storage mutex and then act as it would when receiving a set-cookie-string for the document's address via a "non-HTTP" API, consisting of the new value encoded as UTF-8. [COOKIES] [RFC3629]

Since the cookie attribute is accessible across frames, the path restrictions on cookies are only a tool to help manage which cookies are sent to which parts of the site, and are not in any way a security feature.


document . lastModified

서버에서 보고받은 대로, 이 문서에 마지막 수정이 가해진 날짜를 사용자의 지역 타임존에 맞게
"MM/DD/YYYY hh:mm:ss" 의 형태로 반환합니다.

Returns the date of the last modification to the document, as reported by the server, in the form "MM/DD/YYYY hh:mm:ss", in the user's local time zone.

그러한 시점을 알 수 없다면 현재 시각을 반환합니다.

If the last modification date is not known, the current time is returned instead.

The lastModified attribute, on getting, must return the date and time of the Document's source file's last modification, in the user's local time zone, in the following format:

  1. The month component of the date.
  2. A U+002F SOLIDUS character (/).
  3. The day component of the date.
  4. A U+002F SOLIDUS character (/).
  5. The year component of the date.
  6. A U+0020 SPACE character.
  7. The hours component of the time.
  8. A U+003A COLON character (:).
  9. The minutes component of the time.
  10. A U+003A COLON character (:).
  11. The seconds component of the time.

All the numeric components above, other than the year, must be given as two digits in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9) representing the number in base ten, zero-padded if necessary. The year must be given as the shortest possible string of four or more digits in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9) representing the number in base ten, zero-padded if necessary.

The Document's source file's last modification date and time must be derived from relevant features of the networking protocols used, e.g. from the value of the HTTP Last-Modified header of the document, or from metadata in the file system for local files. If the last modification date and time are not known, the attribute must return the current date and time in the above format.


document . compatMode

올바른 문서에서는 문자열 "CSS1Compat"을 반환합니다. (쿽스 모드 문서에서는 "BackCompat" 문자열을 반환하지만, 올바른 문서는 쿽스 모드에 들어가는 일이 없습니다.)

In a conforming document, returns the string "CSS1Compat". (In quirks mode documents, returns the string "BackCompat", but a conforming document can never trigger quirks mode.)

A Document is always set to one of three modes: no-quirks mode, the default; quirks mode, used typically for legacy documents; and limited-quirks mode, also known as "almost standards" mode. The mode is only ever changed from the default by the HTML parser, based on the presence, absence, or value of the DOCTYPE string.

The compatMode IDL attribute must return the literal string "CSS1Compat" unless the document has been set to quirks mode by the HTML parser, in which case it must instead return the literal string "BackCompat".


document . charset [ = value ]

문서의 문자 인코딩을 반환합니다.

Returns the document's character encoding.

문서의 문자 인코딩을 동적으로 변경하기 위해 설정할 수 있습니다.

Can be set, to dynamically change the document's character encoding.

IANA에 등록되지 않은 것들은 사용자 에이전트가 지원한다 해도 무시됩니다.

New values that are not IANA-registered aliases supported by the user agent are ignored.

document . characterSet

문서의 문자 인코딩을 반환합니다.

Returns the document's character encoding.

document . defaultCharset

사용자 에이전트의 기본 문자 인코딩에 해당하는 것을 반환합니다. (사용자 에이전트는 다른 문자 인코딩을 함께 반환할 수도 있습니다. 예를 들어 사용자의 개인정보를 보호하기 위해서라든가, 사용자 에이전트가 한가지 기본 인코딩을 채택하지 않았을 수도 있습니다.)

Returns what might be the user agent's default character encoding. (The user agent might return another character encoding altogether, e.g. to protect the user's privacy, or if the user agent doesn't use a single default encoding.)

Documents have an associated character encoding. When a Document object is created, the document's character encoding must be initialized to UTF-16. Various algorithms during page loading affect this value, as does the charset setter. [IANACHARSET]

The charset IDL attribute must, on getting, return the preferred MIME name of the document's character encoding. On setting, if the new value is an IANA-registered alias for a character encoding supported by the user agent, the document's character encoding must be set to that character encoding. (Otherwise, nothing happens.)

The characterSet IDL attribute must, on getting, return the preferred MIME name of the document's character encoding.

The defaultCharset IDL attribute must, on getting, return the preferred MIME name of a character encoding, possibly the user's default encoding, or an encoding associated with the user's current geographical location, or any arbitrary encoding name.


document . readyState

Document가 로딩되는 중이라면 loading을, 완전히 로드되면 complete를 반환합니다.

Returns "loading" while the Document is loading, "interactive" once it is finished parsing but still loading sub-resources, and "complete" once it has loaded.

readystatechange 이벤트는 이 값이 바뀔 때 Document 객체에서 발생합니다.

The readystatechange event fires on the Document object when this value changes.

Each document has a current document readiness. When a Document object is created, it must have its current document readiness set to the string "loading" if the document is associated with an HTML parser or an XML parser, or to the string "complete" otherwise. Various algorithms during page loading affect this value. When the value is set, the user agent must fire a simple event named readystatechange at the Document object.

A Document is said to have an active parser if it is associated with an HTML parser or an XML parser that has not yet been stopped or aborted.

The readyState IDL attribute must, on getting, return the current document readiness.

3.1.4 DOM 트리 접근자

문서의 루트 요소는, 그러한 것이 있고 그것이 html 요소라면 html 요소입니다. 아니라면 null입니다.

The html element of a document is the document's root element, if there is one and it's an html element, or null otherwise.


document . head

the head element 요소를 반환합니다.

Returns the head element.

문서의 head 요소는, 그러한 것이 있다면, html 요소head 자식 요소 중 첫 번째 것입니다. 그러한 것이 없다면 null입니다.

The head element of a document is the first head element that is a child of the html element, if there is one, or null otherwise.

The head attribute, on getting, must return the head element of the document (a head element or null).


document . title [ = value ]

title 요소로 주어지는, 문서의 제목을 반환합니다.

Returns the document's title, as given by the title element.

문서의 제목을 갱신하기 위해 설정할 수 있습니다. head 요소가 없다면 새로운 값은 무시합니다.

Can be set, to update the document's title. If there is no head element, the new value is ignored.

SVG 문서에서는, SVGDocument 인터페이스의 title 속성에 우선권이 있습니다.

In SVG documents, the SVGDocument interface's title attribute takes precedence.

문서의 title 요소는 트리 순서로 첫 번째인 title 요소입니다.

The title element of a document is the first title element in the document (in tree order), if there is one, or null otherwise.

The title attribute must, on getting, run the following algorithm:

  1. If the root element is an svg element in the "http://www.w3.org/2000/svg" namespace, and the user agent supports SVG, then return the value that would have been returned by the IDL attribute of the same name on the SVGDocument interface. [SVG]

  2. Otherwise, let value be a concatenation of the data of all the child text nodes of the title element, in tree order, or the empty string if the title element is null.

  3. Replace any sequence of one or more consecutive space characters in value with a single U+0020 SPACE character.

  4. Remove any leading or trailing space characters in value.

  5. Return value.

On setting, the following algorithm must be run. Mutation events must be fired as appropriate.

  1. If the root element is an svg element in the "http://www.w3.org/2000/svg" namespace, and the user agent supports SVG, then the setter must defer to the setter for the IDL attribute of the same name on the SVGDocument interface (if it is readonly, then this will raise an exception). Stop the algorithm here. [SVG]

  2. If the title element is null and the head element is null, then the attribute must do nothing. Stop the algorithm here.
  3. If the title element is null, then a new title element must be created and appended to the head element. Let element be that element. Otherwise, let element be the title element.
  4. The children of element (if any) must all be removed.
  5. A single Text node whose data is the new value being assigned must be appended to element.

The title attribute on the HTMLDocument interface should shadow the attribute of the same name on the SVGDocument interface when the user agent supports both HTML and SVG. [SVG]


document . body [ = value ]

body 요소를 반환합니다.

Returns the body element.

값을 설정해서 body 요소를 바꿀 수 있습니다.

Can be set, to replace the body element.

새로운 값이 body 요소가 아니거나 frameset 요소가 아닐 경우, HIERARCHY_REQUEST_ERR 예외를 반환합니다.

If the new value is not a body or frameset element, this will throw a HIERARCHY_REQUEST_ERR exception.

body 요소html 요소의 첫 번째 자식인, body 혹은 frameset 요소입니다.

The body element of a document is the first child of the html element that is either a body element or a frameset element. If there is no such element, it is null. If the body element is null, then when the specification requires that events be fired at "the body element", they must instead be fired at the Document object.

The body attribute, on getting, must return the body element of the document (either a body element, a frameset element, or null). On setting, the following algorithm must be run:

  1. If the new value is not a body or frameset element, then raise a HIERARCHY_REQUEST_ERR exception and abort these steps.
  2. Otherwise, if the new value is the same as the body element, do nothing. Abort these steps.
  3. Otherwise, if the body element is not null, then replace that element with the new value in the DOM, as if the root element's replaceChild() method had been called with the new value and the incumbent body element as its two arguments respectively, then abort these steps.
  4. Otherwise, the body element is null. Append the new value to the root element.

document . images

Document 내부의 img 요소에 대한 HTMLCollection 반환합니다.

Returns an HTMLCollection of the img elements in the Document.

document . embeds
document . plugins

Document 내부의 embed 요소에 대한 HTMLCollection을 반환합니다.

Return an HTMLCollection of the embed elements in the Document.

document . links

Document 안에 있고 href 속성이 있는 - a, area 요소의 HTMLCollection을 반환합니다.

Returns an HTMLCollection of the a and area elements in the Document that have href attributes.

document . forms

Document 내부의 form 요소에 대한 HTMLCollection을 반환합니다.

Return an HTMLCollection of the form elements in the Document.

document . scripts

Document 내부의 script 요소에 대한 HTMLCollection을 반환합니다.

Return an HTMLCollection of the script elements in the Document.

The images attribute must return an HTMLCollection rooted at the Document node, whose filter matches only img elements.

The embeds attribute must return an HTMLCollection rooted at the Document node, whose filter matches only embed elements.

The plugins attribute must return the same object as that returned by the embeds attribute.

The links attribute must return an HTMLCollection rooted at the Document node, whose filter matches only a elements with href attributes and area elements with href attributes.

The forms attribute must return an HTMLCollection rooted at the Document node, whose filter matches only form elements.

The scripts attribute must return an HTMLCollection rooted at the Document node, whose filter matches only script elements.


collection = document . getElementsByName(name)

name 속성의 값으로 name을 갖는 요소들의 NodeList를 반환합니다.

Returns a NodeList of elements in the Document that have a name attribute with the value name.

collection = document . getElementsByClassName(classes)
collection = element . getElementsByClassName(classes)

메서드의 전치 피연산자(Element 또는 Document)에 속하는 요소 중, classes 클래스를 모두 갖는 것들의 NodeList를 반환합니다.

Returns a NodeList of the elements in the object on which the method was invoked (a Document or an Element) that have all the classes given by classes.

매개변수 classes는 공백문자로 구분된 클래스의 목록으로 해석됩니다. 1)

The classes argument is interpreted as a space-separated list of classes.

The getElementsByName(name) method takes a string name, and must return a live NodeList containing all the HTML elements in that document that have a name attribute whose value is equal to the name argument (in a case-sensitive manner), in tree order. When the method is invoked on a Document object again with the same argument, the user agent may return the same as the object returned by the earlier call. In other cases, a new NodeList object must be returned.

The getElementsByClassName(classNames) method takes a string that contains a set of space-separated tokens representing classes. When called, the method must return a live NodeList object containing all the elements in the document, in tree order, that have all the classes specified in that argument, having obtained the classes by splitting a string on spaces. (Duplicates are ignored.) If there are no tokens specified in the argument, then the method must return an empty NodeList. If the document is in quirks mode, then the comparisons for the classes must be done in an ASCII case-insensitive manner, otherwise, the comparisons must be done in a case-sensitive manner. When the method is invoked on a Document object again with the same argument, the user agent may return the same object as the object returned by the earlier call. In other cases, a new NodeList object must be returned.

The getElementsByClassName(classNames) method on the HTMLElement interface must return a live NodeList with the nodes that the HTMLDocument getElementsByClassName() method would return when passed the same argument(s), excluding any elements that are not descendants of the HTMLElement object on which the method was invoked. When the method is invoked on an HTMLElement object again with the same argument, the user agent may return the same object as the object returned by the earlier call. In other cases, a new NodeList object must be returned.

HTML, SVG, MathML 요소들은 자신이 어느 클래스에 속하는지 정의하기 위해, 네임스페이스를 갖지 않는 class 속성을 사용하며 그 값으로 공백문자로 구분되는 클래스의 목록을 사용합니다. 또한 다른 명세에서 자신의 네임스페이스에 속한 요소들이 특정한 클래스를 갖도록 허용할 수 있습니다.

HTML, SVG, and MathML elements define which classes they are in by having an attribute with no namespace with the name class containing a space-separated list of classes to which the element belongs. Other specifications may also allow elements in their namespaces to be labeled as being in specific classes.

다음의 XHTML 마크업은:

Given the following XHTML fragment:

<div id="example">
 <p id="p1" class="aaa bbb"/>
 <p id="p2" class="aaa ccc"/>
 <p id="p3" class="bbb ccc"/>
</div>

document.getElementById('example').getElementsByClassName('aaa')를 호출하면 p1p2를 포함하는 NodeList를 반환할 것입니다.

A call to document.getElementById('example').getElementsByClassName('aaa') would return a NodeList with the two paragraphs p1 and p2 in it.

getElementsByClassName('ccc bbb')를 호출하면 p3 하나만 반환할 것입니다.
document.getElementById('example').getElementsByClassName('bbb  ccc ')로 호출해도 결과는 같을 것입니다.

A call to getElementsByClassName('ccc bbb') would only return one node, however, namely p3. A call to document.getElementById('example').getElementsByClassName('bbb  ccc ') would return the same thing.

getElementsByClassName('aaa,bbb')로 호출하면 아무런 노드도 반환되지 않을 것입니다. 위의 요소 중 aaa,bbb란 클래스를 갖는 요소는 없습니다.

A call to getElementsByClassName('aaa,bbb') would return no nodes; none of the elements above are in the "aaa,bbb" class.


The HTMLDocument interface supports named properties. The supported property names at any moment consist of the values of the name content attributes of all the applet, embed, form, iframe, img, and fallback-free object elements in the Document that have name content attributes, and the values of the id content attributes of all the applet and fallback-free object elements in the Document that have id content attributes, and the values of the id content attributes of all the img elements in the Document that have both name content attributes and id content attributes.

When the HTMLDocument object is indexed for property retrieval using a name name, then the user agent must return the value obtained using the following steps:

  1. Let elements be the list of named elements with the name name in the Document.

    There will be at least one such element, by definition.

  2. If elements has only one element, and that element is an iframe element, then return the WindowProxy object of the nested browsing context represented by that iframe element, and abort these steps.

  3. Otherwise, if elements has only one element, return that element and abort these steps.

  4. Otherwise return an HTMLCollection rooted at the Document node, whose filter matches only named elements with the name name.

Named elements with the name name, for the purposes of the above algorithm, are those that are either:

An object element is said to be fallback-free if it has no object or embed descendants.


HTMLDocument 인터페이스의 dir 속성은 dir 내용 속성과 같이 정의되었습니다.

The dir attribute on the HTMLDocument interface is defined along with the dir content attribute.

3.1.5 문서 생성

XML 문서DOMImplementation 인터페이스에 createDocument() 메서드를 적용하여 생성할 수 있습니다.

XML documents can be created from script using the createDocument() method on the DOMImplementation interface.

HTML 문서createHTMLDocument() 메서드를 사용하여 생성할 수 있습니다.

HTML documents can be created using the createHTMLDocument() method:

[Supplemental, NoInterfaceObject]
interface DOMHTMLImplementation {
  Document createHTMLDocument(in DOMString title);
};
DOMImplementation implements DOMHTMLImplementation;
document = document . implementation . createHTMLDocument( title )

적합한 title 요소를 갖는, 기본적인 DOM이 이미 구축된 Document를 반환합니다.

Returns a new Document, with a basic DOM already constructed with an appropriate title element.

The createHTMLDocument(title) method, when invoked, must run the following steps:

  1. Let doc be a newly created Document object.

  2. Mark doc as being an HTML document.

  3. Create a DocumentType node with the name attribute set to the string "html", and the other attributes specific to DocumentType objects set to the empty string, null, and empty lists, as appropriate. Append the newly created node to doc.

  4. Create an html element, and append it to doc.

  5. Create a head element, and append it to the html element created in the previous step.

  6. Create a title element, and append it to the head element created in the previous step.

  7. Create a Text node, and set its data attribute to the string given by the method's argument (which could be the empty string). Append it to the title element created in the previous step.

  8. Create a body element, and append it to the html element created in the earlier step.

  9. Return doc.

3.1.6 XML 문서 로딩

A Document object that is an XML document that was created by the DOMImplementation.createDocument() factory method must also implement the XMLDocumentLoader interface:

[Supplemental, NoInterfaceObject]
interface XMLDocumentLoader {
  boolean load(in DOMString url);
};

The load(url) method must run the following steps:

  1. Let document be the Document object on which the method was invoked.

  2. Resolve the method's first argument, relative to the entry script's base URL. If this is not successful, throw a SYNTAX_ERR exception and abort these steps. Otherwise, let url be the resulting absolute URL.

  3. If the origin of url is not the same as the origin of document, throw a SECURITY_ERR exception and abort these steps.

  4. Remove all child nodes of document, without firing any mutation events.

  5. Set the current document readiness of document to "loading".

  6. Run the remainder of these steps asynchronously, and return true from the method.

  7. Let result be an Document object.

  8. Let success be false.

  9. Fetch url from the origin of document, with the synchronous flag set and the force same-origin flag set.

  10. If the fetch attempt was successful, and the resource's Content-Type metadata is an XML MIME type, then run these substeps:

    1. Create a new XML parser associated with the result document.

    2. Pass this parser the fetched document.

    3. If there is an XML well-formedness or XML namespace well-formedness error, then remove all child nodes from result. Otherwise let success be true.

  11. Queue a task to run the following steps.

    1. Set the current document readiness of document to "complete".

    2. Replace all the children of document by the children of result (even if it has no children), firing mutation events as if a DocumentFragment containing the new children had been inserted.

    3. Fire a simple event named load at document.

명세의 해석에 오류가 없다면, 다음과 같은 요소들이 있다고 할 때 :

1) <p class="a b c d">
2) <p class="b c d e">
3) <p class="a c d f">
4) <p class="c b d">

document.getElementsByClassName('b c d')로 요소를 찾는다면 1), 2), 4)에 해당하는 노드리스트를 반환해야 정상적인 구현일 것입니다. 돌아가기