<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Darkmode toggle button for user settings</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121401846" />
  <subtitle>Darkmode toggle button for user settings</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121401846</id>
  <updated>2026-04-07T22:55:13Z</updated>
  <dc:date>2026-04-07T22:55:13Z</dc:date>
  <entry>
    <title>RE: RE: Darkmode toggle button for user settings</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121403107" />
    <author>
      <name>Lena Morawietz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121403107</id>
    <updated>2022-04-20T15:02:10Z</updated>
    <published>2022-04-20T14:48:23Z</published>
    <summary type="html">&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;I corrected the == issue in my code, but forgot to update here. That
  wasn't the problem, but it works now.&lt;/p&gt;
&lt;p&gt;Thanks for you answer.&lt;/p&gt;</summary>
    <dc:creator>Lena Morawietz</dc:creator>
    <dc:date>2022-04-20T14:48:23Z</dc:date>
  </entry>
  <entry>
    <title>RE: Darkmode toggle button for user settings</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121402863" />
    <author>
      <name>Mohammed Yasin</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121402863</id>
    <updated>2022-04-20T15:02:18Z</updated>
    <published>2022-04-20T13:54:08Z</published>
    <summary type="html">&lt;p&gt;Hi ,&lt;/p&gt;
&lt;p&gt;In the condition statement it's supposed to be &amp;quot;==&amp;quot; instead
  of &amp;quot;=&amp;quot; , maybe that's the issue.&lt;/p&gt;
&lt;p&gt;Also you can try below code snippet for the same: &lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;const toggleSwitch = fragmentElement.querySelector('.theme-switch input[type=&amp;quot;checkbox&amp;quot;]');
function updateColor() {
if (document.getElementById(&amp;quot;checkbox&amp;quot;).checked == true) {
	document.documentElement.style.setProperty('bgColor ', '#272833');
    }
    else {    
	document.documentElement.style.setProperty('bgColor ', '#fff');
    }    
}
 toggleSwitch.addEventListener('change', updateColor);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Mohammed Yasin</dc:creator>
    <dc:date>2022-04-20T13:54:08Z</dc:date>
  </entry>
  <entry>
    <title>Darkmode toggle button for user settings</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121401845" />
    <author>
      <name>Lena Morawietz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121401845</id>
    <updated>2022-04-19T17:27:00Z</updated>
    <published>2022-04-19T14:15:25Z</published>
    <summary type="html">&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;I try to add a toggle button to the page to toggle between light and
  dark mode in the settings of the user page, which should be saved. &lt;/p&gt;
&lt;p&gt;I'm using a fragment and only want to change text colors and
  background-color for every page on the site. &lt;/p&gt;
&lt;p&gt;The HTML and CSS of the button works fine but the style of the page
  didn't change because I don't know how to call those specifically in Liferay. &lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-html"&gt;&amp;lt;div class=&amp;quot;mode-toggle&amp;quot;&amp;gt;
	 &amp;lt;label class=&amp;quot;theme-switch&amp;quot; for=&amp;quot;checkbox&amp;quot;&amp;gt;
        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;checkbox&amp;quot; /&amp;gt;
        &amp;lt;div class=&amp;quot;slider round&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/label&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I tried this:&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-javascript"&gt;const toggleSwitch = document.querySelector('.theme-switch input[type=&amp;quot;checkbox&amp;quot;]');

    if (toggleSwitch.checked = true) {
			document.body.bgColor = &amp;quot;#272833&amp;quot;;
			document.body.style.color = &amp;quot;#fff&amp;quot;;
			
    }
    else {        
				document.body.bgColor = &amp;quot;#fff&amp;quot;; 
			document.body.style.color =  &amp;quot;#272833&amp;quot;;
    }    
}
toggleSwitch.addEventListener('change', switchTheme, false);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Lena Morawietz</dc:creator>
    <dc:date>2022-04-19T14:15:25Z</dc:date>
  </entry>
</feed>
