차례
    1. 3.3 HTML 문서의 API
    2. 3.4 XPath, XSLT 와의 상호작용
    3. 3.5 동적 마크업 삽입
      1. 3.5.1 입력 스트림 열기
      2. 3.5.2 입력 스트림 닫기
      3. 3.5.3 document.write()
      4. 3.5.4 document.writeln()
      5. 3.5.5 innerHTML
      6. 3.5.6 outerHTML
      7. 3.5.7 insertAdjacentHTML()

3.3 HTML 문서의 API

HTML 문서와 그러한 문서 내에 있는 HTML 요소에 대해, DOM 코어에 정의된 어떤 API들은 코어의 정의에 따라, 또는 아래에 정리된 내용에 따라 대소문자를 구분하지 않게 되기도 하고, 대소문자가 바뀌기도 합니다. [DOMCORE]

For HTML documents, and for HTML elements in HTML documents, certain APIs defined in DOM Core become case-insensitive or case-changing, as sometimes defined in DOM Core, and as summarized or required below. [DOMCORE]

이러한 것은 XML 문서, 혹은 HTML 문서에 속하기는 하지만 HTML 네임스페이스에 속하지 않는 요소들에는 적용되지 않습니다.

This does not apply to XML documents or to elements that are not in the HTML namespace despite being in HTML documents.

Element.tagName, Node.nodeName

이러한 속성들은 원래 주어졌던 이름과는 관계없이, 요소의 이름을 아스키 대문자로 반환해야 합니다.

These attributes must return element names converted to ASCII uppercase, regardless of the case with which they were created.

Document.createElement()

HTML 마크업의 정규 형태는 모두 소문자입니다. 따라서, 이 메서드는 요청받은 요소를 생성하기 전에 매개변수를 소문자로 변환합니다.

The canonical form of HTML markup is all-lowercase; thus, this method will lowercase the argument before creating the requisite element. Also, the element created must be in the HTML namespace.

이것은 Document.createElementNS() 에는 적용되지 않습니다. 따라서, 이 메서드를 잘못된 철자로 쓰인 tagName에 실행함으로써, 이 명세서에서 정의되어 있는 것처럼 보이지만 인터페이스는 지원하지 못하는 요소를 생성할 가능성이 있습니다. 요소의 "진짜"(대소문자 치환에 영향받지 않은) 이름은 localName 속성에서 얻을 수 있습니다.

This doesn't apply to Document.createElementNS(). Thus, it is possible, by passing this last method a tag name in the wrong case, to create an element that appears to have the same tag name as that of an element defined in this specification when its tagName attribute is examined, but that doesn't support the corresponding interfaces. The "real" element name (unaffected by case conversions) can be obtained from the localName attribute.

Element.setAttribute()
Element.setAttributeNode()

속성의 이름은 아스키 소문자로 치환됩니다.

Attribute names are converted to ASCII lowercase.

Specifically: when an attribute is set on an HTML element using Element.setAttribute(), the name argument must be converted to ASCII lowercase before the element is affected; and when an Attr node is set on an HTML element using Element.setAttributeNode(), it must have its name converted to ASCII lowercase before the element is affected.

이것은 Element.setAttributeNS(), Element.setAttributeNodeNS() 에는 적용되지 않습니다.

This doesn't apply to Element.setAttributeNS() and Element.setAttributeNodeNS().

Element.getAttribute()
Element.getAttributeNode()

속성의 이름은 아스키 소문자로 치환됩니다.

Attribute names are converted to ASCII lowercase.

Specifically: When the Element.getAttribute() method or the Element.getAttributeNode() method is invoked on an HTML element, the name argument must be converted to ASCII lowercase before the element's attributes are examined.

이것은 Element.getAttributeNS(), Element.getAttributeNodeNS() 에는 적용되지 않습니다.

This doesn't apply to Element.getAttributeNS() and Element.getAttributeNodeNS().

Document.getElementsByTagName()
Element.getElementsByTagName()

HTML 요소들은 매개변수들을 먼저 소문자로 치환합니다. 다른 네임스페이스에서 유래한 요소들은 XML과 같습니다. (대소문자를 구분합니다.)

HTML elements match by lower-casing the argument before comparison, elements from other namespaces are treated as in XML (case-sensitively).

Specifically, these methods (but not their namespaced counterparts) must compare the given argument in a case-sensitive manner, but when looking at HTML elements, the argument must first be converted to ASCII lowercase.

따라서, 다양한 네임스페이스로부터 유래한 노드들을 포함하는 HTML 문서에서는, 이러한 메서드들은 대소문자를 구분하기도 하고, 구분하지 않기도 합니다.

Thus, in an HTML document with nodes in multiple namespaces, these methods will effectively be both case-sensitive and case-insensitive at the same time.

3.4 XPath, XSLT 와의 상호작용

Implementations of XPath 1.0 that operate on HTML documents parsed or created in the manners described in this specification (e.g. as part of the document.evaluate() API) must act as if the following edit was applied to the XPath 1.0 specification.

First, remove this paragraph:

A QName in the node test is expanded into an expanded-name using the namespace declarations from the expression context. This is the same way expansion is done for element type names in start and end-tags except that the default namespace declared with xmlns is not used: if the QName does not have a prefix, then the namespace URI is null (this is the same way attribute names are expanded). It is an error if the QName has a prefix for which there is no namespace declaration in the expression context.

Then, insert in its place the following:

A QName in the node test is expanded into an expanded-name using the namespace declarations from the expression context. If the QName has a prefix, then there must be a namespace declaration for this prefix in the expression context, and the corresponding namespace URI is the one that is associated with this prefix. It is an error if the QName has a prefix for which there is no namespace declaration in the expression context.

If the QName has no prefix and the principal node type of the axis is element, then the default element namespace is used. Otherwise if the QName has no prefix, the namespace URI is null. The default element namespace is a member of the context for the XPath expression. The value of the default element namespace when executing an XPath expression through the DOM3 XPath API is determined in the following way:

  1. If the context node is from an HTML DOM, the default element namespace is "http://www.w3.org/1999/xhtml".
  2. Otherwise, the default element namespace URI is null.

This is equivalent to adding the default element namespace feature of XPath 2.0 to XPath 1.0, and using the HTML namespace as the default element namespace for HTML documents. It is motivated by the desire to have implementations be compatible with legacy HTML content while still supporting the changes that this specification introduces to HTML regarding the namespace used for HTML elements, and by the desire to use XPath 1.0 rather than XPath 2.0.

This change is a willful violation of the XPath 1.0 specification, motivated by desire to have implementations be compatible with legacy content while still supporting the changes that this specification introduces to HTML regarding which namespace is used for HTML elements. [XPATH10]


XSLT 1.0 processors outputting to a DOM when the output method is "html" (either explicitly or via the defaulting rule in XSLT 1.0) are affected as follows:

If the transformation program outputs an element in no namespace, the processor must, prior to constructing the corresponding DOM element node, change the namespace of the element to the HTML namespace, ASCII-lowercase the element's local name, and ASCII-lowercase the names of any non-namespaced attributes on the element.

This requirement is a willful violation of the XSLT 1.0 specification, required because this specification changes the namespaces and case-sensitivity rules of HTML in a manner that would otherwise be incompatible with DOM-based XSLT transformations. (Processors that serialize the output are unaffected.) [XSLT10]

3.5 동적 마크업 삽입

동적으로 문서에 마크업을 삽입하는 API들은 파서와 상호작용합니다. 따라서, 그러한 API의 행동 경향은 HTML 문서에서 사용되었는지, XML 문서에서 사용되었는지에 따라 다릅니다.

APIs for dynamically inserting markup into the document interact with the parser, and thus their behavior varies depending on whether they are used with HTML documents (and the HTML parser) or XHTML in XML documents (and the XML parser).

3.5.1 입력 스트림 열기

open() 메서드는 다양한 매개변수에 따라 여러 가지 동작을 합니다.

The open() method comes in several variants with different numbers of arguments.

document = document . open( [ type [, replace ] ] )

Document 객체를, 마치 그것이 새로운 Document인 것처럼 그 자신으로 교체하지만, 이전의 객체를 사용하며 또한 그것을 반환합니다.

Causes the Document to be replaced in-place, as if it was a new Document object, but reusing the previous object, which is then returned.

type 매개변수가 생략되었거나 "text/html"의 값을 가진다면, 결과인 Document는 HTML 파서와 연결됩니다. 이러한 파서는 document.write()를 사용하여 파싱할 수 있는 데이터를 제공합니다. 그렇지 않을 경우, document.write()에 전달되는 모든 내용은 평범한 텍스트로 파싱됩니다.

If the type argument is omitted or has the value "text/html", then the resulting Document has an HTML parser associated with it, which can be given data to parse using document.write(). Otherwise, all content passed to document.write() will be parsed as plain text.

replace 매개변수가 있고 "replace"란 값을 가진다면, Document 객체에 대한 세션 히스토리는 모두 삭제됩니다.

If the replace argument is present and has the value "replace", the existing entries in the session history for the Document object are removed.

이 메서드는 파싱 중인 Document에는 아무런 영향이 없습니다.

The method has no effect if the Document is still being parsed.

XML 문서Document이면 INVALID_STATE_ERR 예외를 반환합니다.

Throws an INVALID_STATE_ERR exception if the Document is an XML document.

window = document . open( url, name, features [, replace ] )

window.open() 메서드와 마찬가지로 동작합니다.

Works like the window.open() method.

When called with two or fewer arguments, the method must act as follows:

  1. If the Document object is not flagged as an HTML document, throw an INVALID_STATE_ERR exception and abort these steps.
  2. Let type be the value of the first argument, if there is one, or "text/html" otherwise.

  3. Let replace be true if there is a second argument and it is an ASCII case-insensitive match for the value "replace", and false otherwise.

  4. If the document has an active parser that isn't a script-created parser, and the insertion point associated with that parser's input stream is not undefined (that is, it does point to somewhere in the input stream), then the method does nothing. Abort these steps and return the Document object on which the method was invoked.

    This basically causes document.open() to be ignored when it's called in an inline script found during the parsing of data sent over the network, while still letting it have an effect when called asynchronously or on a document that is itself being spoon-fed using these APIs.

  5. Release the storage mutex.

  6. Prompt to unload the Document object. If the user refused to allow the document to be unloaded, then these steps must be aborted.

  7. Unload the Document object, with the recycle parameter set to true.

  8. Abort the Document.

  9. Unregister all event listeners registered on the Document node and its descendants.

  10. Remove any tasks associated with the Document in any task source.

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

  12. Replace the Document's singleton objects with new instances of those objects. (This includes in particular the Window, Location, History, ApplicationCache, and Navigator, objects, the various BarProp objects, the two Storage objects, the various HTMLCollection objects, and objects defined by other specifications, like Selection. It also includes all the Web IDL prototypes in the JavaScript binding, including the Document object's prototype.)

  13. Change the document's character encoding to UTF-8.

  14. Set the Document object's reload override flag and set the Document's reload override buffer to the empty string.

  15. Change the document's address to the entry script's document's address.

  16. Create a new HTML parser and associate it with the document. This is a script-created parser (meaning that it can be closed by the document.open() and document.close() methods, and that the tokenizer will wait for an explicit call to document.close() before emitting an end-of-file token). The encoding confidence is irrelevant.

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

  18. If the type string contains a U+003B SEMICOLON character (;), remove the first such character and all characters from it up to the end of the string.

    Strip all leading and trailing space characters from type.

    If type is not now an ASCII case-insensitive match for the string "text/html", then act as if the tokenizer had emitted a start tag token with the tag name "pre" followed by a single U+000A LINE FEED (LF) character, then switch the HTML parser's tokenizer to the PLAINTEXT state.

  19. Remove all the entries in the browsing context's session history after the current entry. If the current entry is the last entry in the session history, then no entries are removed.

    This doesn't necessarily have to affect the user agent's user interface.

  20. Remove any tasks queued by the history traversal task source.

  21. Remove any earlier entries that share the same Document.
  22. If replace is false, then add a new entry, just before the last entry, and associate with the new entry the text that was parsed by the previous parser associated with the Document object, as well as the state of the document at the start of these steps. (This allows the user to step backwards in the session history to see the page before it was blown away by the document.open() call.)

  23. Finally, set the insertion point to point at just before the end of the input stream (which at this point will be empty).

  24. Return the Document on which the method was invoked.

When called with three or more arguments, the open() method on the HTMLDocument object must call the open() method on the Window object of the HTMLDocument object, with the same arguments as the original call to the open() method, and return whatever that method returned. If the HTMLDocument object has no Window object, then the method must raise an INVALID_ACCESS_ERR exception.

3.5.2 입력 스트림 닫기

document . close()

document.open() 메서드로 시작된 입력 스트림을 닫습니다.

Closes the input stream that was opened by the document.open() method.

XML 문서Document이면 INVALID_STATE_ERR 예외를 반환합니다.

Throws an INVALID_STATE_ERR exception if the Document is an XML document.

The close() method must run the following steps:

  1. If the Document object is not flagged as an HTML document, throw an INVALID_STATE_ERR exception and abort these steps.

  2. If there is no script-created parser associated with the document, then abort these steps.

  3. Insert an explicit "EOF" character at the end of the parser's input stream.

  4. If there is a pending parsing-blocking script, then abort these steps.

  5. Run the tokenizer, processing resulting tokens as they are emitted, and stopping when the tokenizer reaches the explicit "EOF" character or spins the event loop.

3.5.3 document.write()

document . write(text...)

일반적으로, 주어진 문자열을 Document의 입력 스트림에 추가합니다.

In general, adds the given string(s) to the Document's input stream.

이 메서드는 대단히 기이하게 동작합니다. 일부의 경우, 이 메서드는 HTML 파서가 동작하는 동안에 그 상태에 영향을 미치며, 결과적으로 DOM이 문서의 원본에 대응하지 않게 됩니다. 다른 경우, 메서드에 대한 호출은 현재의 페이지를, 마치 document.open() 메서드가 호출되었던 것처럼, 삭제할 수 있습니다. 그 외에 많은 경우에서, 이 메서드는 단순히 무시되거나, 또는 예외를 반환합니다. 문제를 더욱 심각하게 만드는 것은, 때때로 이 메서드의 정확한 동작이 네트워크의 응답 속도에 영향을 받을 수 있기 때문에, 디버그하기 대단히 어려운 문제들이 생길 수 있습니다. 이러한 모든 이유로, 이 메서드를 사용하지 않기를 강력히 권합니다.

This method has very idiosyncratic behavior. In some cases, this method can affect the state of the HTML parser while the parser is running, resulting in a DOM that does not correspond to the source of the document. In other cases, the call can clear the current page first, as if document.open() had been called. In yet more cases, the method is simply ignored, or throws an exception. To make matters worse, the exact behavior of this method can in some cases be dependent on network latency, which can lead to failures that are very hard to debug. For all these reasons, use of this method is strongly discouraged.

XML 문서에서 호출되면 INVALID_STATE_ERR 예외를 반환합니다.

This method throws an INVALID_STATE_ERR exception when invoked on XML documents.

Document objects have an ignore-destructive-writes counter, which is used in conjunction with the processing of script elements to prevent external scripts from being able to use document.write() to blow away the document by implicitly calling document.open(). Initially, the counter must be set to zero.

The document.write(...) method must act as follows:

  1. If the method was invoked on an XML document, throw an INVALID_STATE_ERR exception and abort these steps.

  2. If the insertion point is undefined and the Document's ignore-destructive-writes counter is greater than zero, then abort these steps.

  3. If the insertion point is undefined, call the open() method on the document object (with no arguments). If the user refused to allow the document to be unloaded, then abort these steps. Otherwise, the insertion point will point at just before the end of the (empty) input stream.

  4. Insert the string consisting of the concatenation of all the arguments to the method into the input stream just before the insertion point.

  5. If the Document object's reload override flag is set, then append the string consisting of the concatenation of all the arguments to the method to the Document's reload override buffer.

  6. If there is no pending parsing-blocking script, have the tokenizer process the characters that were inserted, one at a time, processing resulting tokens as they are emitted, and stopping when the tokenizer reaches the insertion point or when the processing of the tokenizer is aborted by the tree construction stage (this can happen if a script end tag token is emitted by the tokenizer).

    If the document.write() method was called from script executing inline (i.e. executing because the parser parsed a set of script tags), then this is a reentrant invocation of the parser.

  7. Finally, return from the method.

3.5.4 document.writeln()

document . writeln(text...)

주어진 문자열을 Document의 입력 흐름에 더합니다. 이러한 삽입을 한 후 줄바꿈 문자를 추가합니다. 필요하다면, open() 메서드를 먼저 암시적으로 호출합니다.

Adds the given string(s) to the Document's input stream, followed by a newline character. If necessary, calls the open() method implicitly first.

XML 문서에서 호출되면 INVALID_STATE_ERR 예외를 반환합니다.

This method throws an INVALID_STATE_ERR exception when invoked on XML documents.

The document.writeln(...) method, when invoked, must act as if the document.write() method had been invoked with the same argument(s), plus an extra argument consisting of a string containing a single line feed character (U+000A).

3.5.5 innerHTML

IDL 속성 innerHTML 노드 내용의 마크업을 나타냅니다.

The innerHTML IDL attribute represents the markup of the node's contents.

document . innerHTML [ = value ]

Document를 나타내는 HTML, 또는 XML 을 반환합니다.

Returns a fragment of HTML or XML that represents the Document.

주어진 문자열을 파싱한 결과가 Document의 내용이 되도록 설정할 수 있습니다.

Can be set, to replace the Document's contents with the result of parsing the given string.

XML 문서의 경우, Document를 XML로 직렬화할 수 없으면 INVALID_STATE_ERR 예외를 반환하며, 주어진 문자열이 정확한 형태가 아니라면 SYNTAX_ERR 예외를 반환합니다.

In the case of XML documents, will throw an INVALID_STATE_ERR if the Document cannot be serialized to XML, and a SYNTAX_ERR if the given string is not well-formed.

element . innerHTML [ = value ]

요소의 내용을 나타내는 HTML, 또는 XML 을 반환합니다.

Returns a fragment of HTML or XML that represents the element's contents.

주어진 문자열을 파싱한 결과가 요소의 내용이 되도록 설정할 수 있습니다.

Can be set, to replace the contents of the element with nodes parsed from the given string.

XML 문서의 경우, 요소가 XML로 직렬화될 수 없으면 INVALID_STATE_ERR 예외를 반환하며, 주어진 문자열이 정확한 형태가 아니라면 SYNTAX_ERR 예외를 반환합니다.

In the case of XML documents, will throw an INVALID_STATE_ERR if the element cannot be serialized to XML, and a SYNTAX_ERR if the given string is not well-formed.

On getting, if the node's document is an HTML document, then the attribute must return the result of running the HTML fragment serialization algorithm on the node; otherwise, the node's document is an XML document, and the attribute must return the result of running the XML fragment serialization algorithm on the node instead (this might raise an exception instead of returning a string).

On setting, the following steps must be run:

  1. If the node's document is an HTML document: Invoke the HTML fragment parsing algorithm.

    If the node's document is an XML document: Invoke the XML fragment parsing algorithm.

    In either case, the algorithm must be invoked with the string being assigned into the innerHTML attribute as the input. If the node is an Element node, then, in addition, that element must be passed as the context element.

    If this raises an exception, then abort these steps.

    Otherwise, let new children be the nodes returned.

  2. If the attribute is being set on a Document node, and that document has an active parser, then abort that parser.

  3. Remove the child nodes of the node whose innerHTML attribute is being set, firing appropriate mutation events.

  4. If the attribute is being set on a Document node, let target document be that Document node. Otherwise, the attribute is being set on an Element node; let target document be the ownerDocument of that Element.

  5. Set the ownerDocument of all the nodes in new children to the target document.

  6. Append all the new children nodes to the node whose innerHTML attribute is being set, preserving their order, and firing mutation events as if a DocumentFragment containing the new children had been inserted.

3.5.6 outerHTML

IDL 속성 outerHTML은 요소와 그 내용의 마크업을 나타냅니다.

The outerHTML IDL attribute represents the markup of the element and its contents.

element . outerHTML [ = value ]

요소와 그 내용을 나타내는 HTML, 또는 XML 조각을 반환합니다.

Returns a fragment of HTML or XML that represents the element and its contents.

그러한 문자열을 파싱한 노드가 요소를 대체하도록 설정할 수 있습니다.

Can be set, to replace the element with nodes parsed from the given string.

XML 문서의 경우, 요소가 XML로 직렬화될 수 없으면 INVALID_STATE_ERR 예외를 반환하며, 주어진 문자열이 정확한 형태가 아니라면 SYNTAX_ERR 예외를 반환합니다.

In the case of XML documents, will throw an INVALID_STATE_ERR if the element cannot be serialized to XML, and a SYNTAX_ERR if the given string is not well-formed.

요소의 부모가 Document 노드일 경우 NO_MODIFICATION_ALLOWED_ERR 예외를 반환합니다.

Throws a NO_MODIFICATION_ALLOWED_ERR exception if the parent of the element is the Document node.

On getting, if the node's document is an HTML document, then the attribute must return the result of running the HTML fragment serialization algorithm on a fictional node whose only child is the node on which the attribute was invoked; otherwise, the node's document is an XML document, and the attribute must return the result of running the XML fragment serialization algorithm on that fictional node instead (this might raise an exception instead of returning a string).

On setting, the following steps must be run:

  1. Let target be the element whose outerHTML attribute is being set.

  2. If target has no parent node, then abort these steps. There would be no way to obtain a reference to the nodes created even if the remaining steps were run.

  3. If target's parent node is a Document object, throw a NO_MODIFICATION_ALLOWED_ERR exception and abort these steps.

  4. Let parent be target's parent node, unless that is a DocumentFragment node, in which case let parent be an arbitrary body element.

  5. If target's document is an HTML document: Invoke the HTML fragment parsing algorithm.

    If target's document is an XML document: Invoke the XML fragment parsing algorithm.

    In either case, the algorithm must be invoked with the string being assigned into the outerHTML attribute as the input, and parent as the context element.

    If this raises an exception, then abort these steps.

    Otherwise, let new children be the nodes returned.

  6. Set the ownerDocument of all the nodes in new children to target's document.

  7. Remove target from its parent node, firing mutation events as appropriate, and then insert in its place all the new children nodes, preserving their order, and again firing mutation events as if a DocumentFragment containing the new children had been inserted.

3.5.7 insertAdjacentHTML()

element . insertAdjacentHTML(position, text)

주어진 문자열, text를 HTML 또는 XML로 파싱하고, 그 결과로 생성된 노드를 position 매개변수가 지정하는 위치에 삽입합니다.

Parses the given string text as HTML or XML and inserts the resulting nodes into the tree in the position given by the position argument, as follows:

"beforebegin"

요소의 앞

Before the element itself.

"afterbegin"

요소의 내부, 첫 번째 자식 요소 앞

Just inside the element, before its first child.

"beforeend"

요소의 내부, 마지막 자식 요소 뒤

Just inside the element, after its last child.

"afterend"

요소의 뒤

After the element itself.

매개변수가 잘못된 값을 가졌을 경우(예를 들어, XML 문서에서 주어진 문자열이 올바르게 정규화 되어 있지 않은 경우) SYNTAX_ERR 예외를 반환합니다.

Throws a SYNTAX_ERR exception if the arguments have invalid values (e.g., in the case of XML documents, if the given string is not well-formed).

주어진 위치에 삽입할 수 없으면(예를 들어, Document의 루트 요소 뒤에 삽입하려 했을 때)
NO_MODIFICATION_ALLOWED_ERR 예외를 반환합니다.

Throws a NO_MODIFICATION_ALLOWED_ERR exception if the given position isn't possible (e.g. inserting elements after the root element of a Document).

The insertAdjacentHTML(position, text) method, when invoked, must run the following algorithm:

  1. Let position and text be the method's first and second arguments, respectively.

  2. Let target be the element on which the method was invoked.

  3. Use the first matching item from this list:

    If position is an ASCII case-insensitive match for the string "beforebegin"
    If position is an ASCII case-insensitive match for the string "afterend"

    If target has no parent node, then abort these steps.

    If target's parent node is a Document object, then throw a NO_MODIFICATION_ALLOWED_ERR exception and abort these steps.

    Otherwise, let context be the parent node of target.

    If position is an ASCII case-insensitive match for the string "afterbegin"
    If position is an ASCII case-insensitive match for the string "beforeend"

    Let context be the same as target.

    Otherwise

    Throw a SYNTAX_ERR exception.

  4. If target's document is an HTML document: Invoke the HTML fragment parsing algorithm.

    If target's document is an XML document: Invoke the XML fragment parsing algorithm.

    In either case, the algorithm must be invoked with text as the input, and the element selected in by the previous step as the context element.

    If this raises an exception, then abort these steps.

    Otherwise, let new children be the nodes returned.

  5. Set the ownerDocument of all the nodes in new children to target's document.

  6. Use the first matching item from this list:

    If position is an ASCII case-insensitive match for the string "beforebegin"

    Insert all the new children nodes immediately before target.

    If position is an ASCII case-insensitive match for the string "afterbegin"

    Insert all the new children nodes before the first child of target, if there is one. If there is no such child, append them all to target.

    If position is an ASCII case-insensitive match for the string "beforeend"

    Append all the new children nodes to target.

    If position is an ASCII case-insensitive match for the string "afterend"

    Insert all the new children nodes immediately after target.

    The new children nodes must be inserted in a manner that preserves their order and fires mutation events as if a DocumentFragment containing the new children had been inserted.