Skip to content
// Wait for the theme-switch button to exist, then attach the click
const observer = new MutationObserver(function(mutations, obs) {
const wrapper = document.querySelector('.theme-switch .elementor-button');
if (wrapper) {
const buttonText = wrapper.querySelector('.elementor-button-text');
const html = document.documentElement;
wrapper.addEventListener('click', function(e) {
e.preventDefault();
const currentTheme = html.getAttribute('data-theme') || 'light';
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
if (buttonText) buttonText.textContent = newTheme === 'dark' ? '🌙' : '☀️';
});
console.log('Theme switch JS attached');
obs.disconnect(); // stop observing once attached
}
});
// Observe the whole document body for changes
observer.observe(document.body, { childList: true, subtree: true });