Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript detect dark mode

const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
Comment

detect dark mode javascript

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    console.log(` is dark`);
}else{
  console.log(`shiit is light`);
}
Comment

detect system dark mode javascrip

 const darkTheme = window.matchMedia("(prefers-color-scheme: dark)");
  if (darkTheme.matches) {
       document.documentElement.classList.add("dark");
    } else {
      document.documentElement.classList.remove("dark");
       }
Comment

javascript detect dark mode

const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches

console.log(isDarkMode) // Result: True or False
Comment

js if dark mode

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    // dark mode
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery get element id 
Javascript :: how to drawImage on center of canvas 
Javascript :: $(document).ready | document.ready 
Javascript :: js stop form submit on enter 
Javascript :: window.href 
Javascript :: document get element by tag 
Javascript :: how to see if user clicked key in js 
Javascript :: node js pre-commit hook bypass 
Javascript :: how to play jquery audio 
Javascript :: nodejs ask for input 
Javascript :: datatable default sorting 
Javascript :: regex between quotes 
Javascript :: graphqlHTTP is not a function 
Javascript :: jquery json decode 
Javascript :: how to open a new tab in react 
Javascript :: add select option javascript 
Javascript :: get user language js 
Javascript :: dropzone clear files 
Javascript :: material-ui hover style 
Javascript :: how to detect safari browser in javascript 
Javascript :: js fake promise with timeout 
Javascript :: readonly attribute in html by javascript 
Javascript :: how to clear nodemon cache 
Javascript :: express get full url 
Javascript :: resolveJsonModule 
Javascript :: js array enclose all items with ' 
Javascript :: react-native release build 
Javascript :: document ready 
Javascript :: javascript moeda reais 
Javascript :: valid email patter check jquery 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =