Skip to content

Commit a688bcf

Browse files
authored
Simplify access to html element in dark mode snippet (#721)
https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement
1 parent b36669f commit a688bcf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/pages/docs/dark-mode.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ Here's a simple example of how you can support light mode, dark mode, as well as
115115
```js
116116
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
117117
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
118-
document.querySelector('html').classList.add('dark')
118+
document.documentElement.classList.add('dark')
119119
} else {
120-
document.querySelector('html').classList.remove('dark')
120+
document.documentElement.classList.remove('dark')
121121
}
122122

123123
// Whenever the user explicitly chooses light mode

0 commit comments

Comments
 (0)