diff --git a/files/en-us/web/api/element/attachshadow/index.md b/files/en-us/web/api/element/attachshadow/index.md index e6fdc1be2e45f1d..f28cbe2073891e4 100644 --- a/files/en-us/web/api/element/attachshadow/index.md +++ b/files/en-us/web/api/element/attachshadow/index.md @@ -83,6 +83,12 @@ attachShadow(options) - : A boolean that, when set to `true`, specifies behavior that mitigates custom element issues around focusability. When a non-focusable part of the shadow DOM is clicked, the first focusable part is given focus, and the shadow host is given any available `:focus` styling. Its default value is `false`. + - `serializable` {{Optional_Inline}} + + - : A boolean that, when set to `true`, indicates that the shadow root is serializable. + If set, the shadow root may be serialized by calling the {{DOMxRef('Element.getHTML()')}} or {{DOMxRef('ShadowRoot.getHTML()')}} methods with the `options.serializableShadowRoots` parameter set `true`. + Its default value is `false`. + - `slotAssignment` {{Optional_inline}} - : A string specifying the _slot assignment mode_ for the shadow DOM tree. This can be one of: diff --git a/files/en-us/web/api/element/gethtml/index.md b/files/en-us/web/api/element/gethtml/index.md index 133d548ca0b4091..d00223564f14f37 100644 --- a/files/en-us/web/api/element/gethtml/index.md +++ b/files/en-us/web/api/element/gethtml/index.md @@ -12,10 +12,15 @@ browser-compat: api.Element.getHTML The **`getHTML()`** method of the {{domxref("Element")}} interface is used to serialize an element's DOM to an HTML string. +The method provides an options argument that enables the serialization of child nodes that are shadow roots. +The options can be used to include nested shadow roots that have been set as {{domxref("ShadowRoot/serializable","serializable")}}, and/or a specified array of {{domxref("ShadowRoot")}} objects, which may be either open or closed. + +Without arguments, child nodes that are shadow roots are not serialized, and this method behaves in the same way as reading the value of {{domxref("Element.innerHTML")}}. + ## Syntax ```js-nolint -const html = element.getHTML(options) +getHTML(options) ``` ### Parameters @@ -25,10 +30,12 @@ const html = element.getHTML(options) - : An options object with the following optional parameters: - `serializableShadowRoots` - - : A boolean value that specifies whether to include serializable shadow roots. The default value is `false`. + - : A boolean value that specifies whether to include {{domxref("ShadowRoot/serializable","serializable")}} shadow roots. + The default value is `false`. - `shadowRoots` - - : An array of {{domxref("ShadowRoot")}} objects to serialize. These are included regardless of whether they - are marked as serializable. The default value is an empty array. + - : An array of {{domxref("ShadowRoot")}} objects to serialize. + These are included regardless of whether they are marked as `serializable`, or if they are open or closed. + The default value is an empty array. ### Return value @@ -50,3 +57,5 @@ None. - {{domxref("ShadowRoot.getHTML()")}} - {{domxref("Element.innerHTML")}} +- {{domxref("Element.setHTMLUnsafe()")}} +- {{domxref("ShadowRoot.setHTMLUnsafe()")}} diff --git a/files/en-us/web/api/element/innerhtml/index.md b/files/en-us/web/api/element/innerhtml/index.md index d6a6adee7aafa9a..6c21690218d9de3 100644 --- a/files/en-us/web/api/element/innerhtml/index.md +++ b/files/en-us/web/api/element/innerhtml/index.md @@ -8,36 +8,36 @@ browser-compat: api.Element.innerHTML {{APIRef("DOM")}} -The {{domxref("Element")}} property -**`innerHTML`** gets or sets the HTML or XML markup contained -within the element. +The {{domxref("Element")}} property **`innerHTML`** gets or sets the HTML or XML markup contained within the element. -To insert the HTML into the document rather than replace the contents of an element, -use the method {{domxref("Element.insertAdjacentHTML", "insertAdjacentHTML()")}}. +More precisely, `innerHTML` gets a serialization of the nested child DOM elements within the element, or sets HTML or XML that should be parsed to replace the DOM tree within the element. + +To insert the HTML into the document rather than replace the contents of an element, use the method {{domxref("Element.insertAdjacentHTML", "insertAdjacentHTML()")}}. + +The serialization of the DOM tree read from the property does not include {{glossary("shadow tree", "shadow roots")}} — if you want to get a HTML string that includes shadow roots, you must instead use the {{domxref("Element.getHTML()")}} or {{domxref("ShadowRoot.getHTML()")}} methods. +Similarly, when setting element content using `innerHTML`, the HTML string is parsed into DOM elements that do not contain shadow roots. + +So for example [`