From 26ce8342678fea9d3ae7eae67ab3318168bb8ab2 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Wed, 8 May 2024 15:19:45 +0100 Subject: [PATCH] Add initial content for setHTMLUnsafe and parseHTMLUnsafe --- .../document/parsehtmlunsafe_static/index.md | 43 ++++++++++++++ .../web/api/element/sethtmlunsafe/index.md | 56 +++++++++++++++++++ .../web/api/shadowroot/sethtmlunsafe/index.md | 43 ++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 files/en-us/web/api/document/parsehtmlunsafe_static/index.md create mode 100644 files/en-us/web/api/element/sethtmlunsafe/index.md create mode 100644 files/en-us/web/api/shadowroot/sethtmlunsafe/index.md diff --git a/files/en-us/web/api/document/parsehtmlunsafe_static/index.md b/files/en-us/web/api/document/parsehtmlunsafe_static/index.md new file mode 100644 index 000000000000000..842ebeadc2c7f71 --- /dev/null +++ b/files/en-us/web/api/document/parsehtmlunsafe_static/index.md @@ -0,0 +1,43 @@ +--- +title: "Document: parseHTMLUnsafe() static method" +short-title: parseHTMLUnsafe() +slug: Web/API/Document/parseHTMLUnsafe_static +page-type: web-api-static-method +browser-compat: api.Document.parseHTMLUnsafe_static +--- + +{{APIRef("DOM")}}{{SeeCompatTable}}{{SecureContext_Header}} + +The **`Document.parseHTMLUnsafe()`** static method is used to parse a string of HTML as a new document object. + +## Syntax + +```js-nolint +const doc = Document.parseHTMLUnsafe(input) +``` + +### Parameters + +- `input` + - : A string defining HTML to be parsed. + +### Return value + +A {{domxref("Document")}}. + +### Exceptions + +None. + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- Parsing HTML or XML into a DOM tree: {{domxref("DOMParser")}} +- {{domxref("Element.setHTMLUnsafe")}} diff --git a/files/en-us/web/api/element/sethtmlunsafe/index.md b/files/en-us/web/api/element/sethtmlunsafe/index.md new file mode 100644 index 000000000000000..b03bceb68387337 --- /dev/null +++ b/files/en-us/web/api/element/sethtmlunsafe/index.md @@ -0,0 +1,56 @@ +--- +title: "Element: setHTMLUnsafe() method" +short-title: setHTMLUnsafe() +slug: Web/API/Element/setHTMLUnsafe +page-type: web-api-instance-method +browser-compat: api.Element.setHTMLUnsafe +--- + +{{APIRef("DOM")}}{{SeeCompatTable}}{{SecureContext_Header}} + +The **`setHTMLUnsafe()`** method of the {{domxref("Element")}} interface is used to parse a string of HTML and then insert it into the DOM as a subtree of the element. + +## Syntax + +```js-nolint +element.setHTMLUnsafe(input) +``` + +### Parameters + +- `input` + - : A string defining HTML to be parsed. + +### Return value + +None (`undefined`). + +### Exceptions + +None. + +## Examples + +The code below demonstrates how to parse a string of HTML and insert it into the `Element` with an id of `target`. + +```js +const value = "

This is a string of text

"; // string of HTML + +// Get the Element with id "target" and set it with the string. +document.getElementById("target").setHTMLUnsafe(value); + +// Result (as a string): "

This is a string of text

" +``` + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("Element.innerHTML")}} +- {{domxref("Document.parseHTMLUnsafe_static", "Document.parseHTMLUnsafe()")}} diff --git a/files/en-us/web/api/shadowroot/sethtmlunsafe/index.md b/files/en-us/web/api/shadowroot/sethtmlunsafe/index.md new file mode 100644 index 000000000000000..0da97af325a67df --- /dev/null +++ b/files/en-us/web/api/shadowroot/sethtmlunsafe/index.md @@ -0,0 +1,43 @@ +--- +title: "ShadowRoot: setHTMLUnsafe() method" +short-title: setHTMLUnsafe() +slug: Web/API/ShadowRoot/setHTMLUnsafe +page-type: web-api-instance-method +browser-compat: api.ShadowRoot.setHTMLUnsafe +--- + +{{APIRef("DOM")}}{{SeeCompatTable}}{{SecureContext_Header}} + +The **`setHTMLUnsafe()`** method of the {{domxref("ShadowRoot")}} interface is used to parse a string of HTML and then insert it into the DOM as a subtree of the shadow root. + +## Syntax + +```js-nolint +shadowRoot.setHTMLUnsafe(input) +``` + +### Parameters + +- `input` + - : A string defining HTML to be parsed. + +### Return value + +None (`undefined`). + +### Exceptions + +None. + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("ShadowRoot.innerHTML")}} +- {{domxref("Document.parseHTMLUnsafe_static", "Document.parseHTMLUnsafe()")}}