Skip to content

Commit

Permalink
Add initial content for setHTMLUnsafe and parseHTMLUnsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewarlow committed May 8, 2024
1 parent e04783b commit ee3aa4c
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
43 changes: 43 additions & 0 deletions files/en-us/web/api/document/parsehtmlunsafe_static/index.md
Original file line number Diff line number Diff line change
@@ -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")}}
56 changes: 56 additions & 0 deletions files/en-us/web/api/element/sethtmlunsafe/index.md
Original file line number Diff line number Diff line change
@@ -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 = "<p>This is a string of text</p>"; // string of HTML

// Get the Element with id "target" and set it with the string.
document.getElementById("target").setHTMLUnsafe(value);

// Result (as a string): "<p>This is a string of text</p>"
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("Element.innerHTML")}}
- {{domxref("Document.parseHTMLUnsafe_static")}}
43 changes: 43 additions & 0 deletions files/en-us/web/api/shadowroot/sethtmlunsafe/index.md
Original file line number Diff line number Diff line change
@@ -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")}}

0 comments on commit ee3aa4c

Please sign in to comment.