MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Functions
jq Library dialog alert confirm prompt snackbar getTheme setTheme getColorFromImage setColorScheme removeColorScheme loadLocale setLocale getLocale throttle observeResize breakpoint
Libraries

getTheme

The getTheme function returns the current theme applied to the page or a specific element.

The available themes are light, dark, and auto. For more information, see the Dark Mode section.

Usage

Import the function:

import { getTheme } from 'mdui/functions/getTheme.js';

Example:

// Get the theme on <html>
getTheme();

// Get the theme on an element with class="element"
getTheme('.element');

// Get the theme on a specified DOM element
const element = document.querySelector('.element');
getTheme(element);

API

getTheme(target?: string | HTMLElement | JQ<HTMLElement>): 'light' | 'dark' | 'auto'

This function retrieves the theme of a specified element. The target can be a CSS selector, a DOM element, or a JQ object. If no target is provided, it defaults to the <html> element.

The function returns light, dark, or auto. If no theme is set on the element, it defaults to light.

On this page