Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions files/en-us/web/api/document/adoptedstylesheets/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const sheet = new CSSStyleSheet();
sheet.replaceSync("a { color: red; }");

// Apply the stylesheet to a document
document.adoptedStyleSheets = [sheet];
document.adoptedStyleSheets.push(sheet);
```

We can append a new rule to the stylesheet using {{domxref("CSSStyleSheet.insertRule()")}}.
Expand All @@ -58,19 +58,6 @@ sheet.insertRule("* { background-color: blue; }");
// The document will now have blue background.
```

### Append a new stylesheet

To append a whole new stylesheet to the `adoptedStyleSheets` property we have to create and assign a new combined array.
This is demonstrated below using spread-syntax:

```js
const extraSheet = new CSSStyleSheet();
extraSheet.replaceSync("p { color: green; }");

// Combine the existing sheets and new one
document.adoptedStyleSheets = [...document.adoptedStyleSheets, extraSheet];
```

## Sharing a stylesheet with a shadow DOM

We can share a stylesheet to a shadow root in a similar way.
Expand Down