CSSStyleSheet: replaceSync() メソッド
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
replaceSync()
は CSSStyleSheet
インターフェイスのメソッドで、スタイルシートの内容を渡された内容で同期的に置き換えます。
replaceSync()
と CSSStyleSheet.replace()
の両メソッドは、 CSSStyleSheet()
コンストラクターで作成されたスタイルシートでのみ使用できます。
構文
js
replaceSync(text)
引数
返値
なし (undefined
)。
例外
NotAllowedError
DOMException
-
このスタイルシートが
CSSStyleSheet()
コンストラクターを使用して作成されていない場合、または変更不可に設定されている場合に発生します。
例
次の例では、新しいスタイルシートを作成し、replaceSync()
を使って 2 つの CSS ルールを追加しています。
js
const stylesheet = new CSSStyleSheet();
stylesheet.replaceSync("body { font-size: 1.4em; } p { color: red; }");
仕様書
Specification |
---|
CSS Object Model (CSSOM) # dom-cssstylesheet-replacesync |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
replaceSync |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
関連情報
- Constructable Stylesheets (web.dev)
- シャドウ DOM の使用