<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Miranda Washburn on Medium]]></title>
        <description><![CDATA[Stories by Miranda Washburn on Medium]]></description>
        <link>https://medium.com/@mirandawashburn?source=rss-4adb653e1b0d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*EKZgf9UgfaRiEj2C.</url>
            <title>Stories by Miranda Washburn on Medium</title>
            <link>https://medium.com/@mirandawashburn?source=rss-4adb653e1b0d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 15:18:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mirandawashburn/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Notes App with Local Storage]]></title>
            <link>https://medium.com/@mirandawashburn/notes-app-with-local-storage-14165975ba86?source=rss-4adb653e1b0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/14165975ba86</guid>
            <category><![CDATA[localstorage]]></category>
            <category><![CDATA[notes]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Miranda Washburn]]></dc:creator>
            <pubDate>Sat, 26 Oct 2019 00:17:37 GMT</pubDate>
            <atom:updated>2019-10-26T00:17:37.373Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*3Wps-jwoNtmiywz0aATT3A.jpeg" /></figure><h3>Setting Up the HTML</h3><p>I started with a section tag with a class name of ‘note’. Then, added a text input type for the notes title. Afterwards, I added a textarea tag for the body of the note.</p><p>I added an onchange function to both the textarea and input tags to run the Javascript. I also included a div with a ‘test’ id, so show an error message if a web browser doesn’t support local storage.</p><p>Here’s the code:</p><pre>&lt;section class=&#39;note&#39;&gt;<br>  &lt;input type=&quot;text&quot; placeholder=&quot;Note Title&quot; id=&quot;title&quot; value=&quot;&quot; onchange=&quot;saveTitle()&quot;&gt;&lt;/input&gt;<br>  &lt;textarea placeholder=&quot;Write a note, and refresh your browser to see how it saves!&quot; id=&quot;message&quot; onchange=&quot;saveMessage()&quot;&gt;<br>  &lt;/textarea&gt;<br>&lt;/section&gt;</pre><pre>&lt;!--- Shows error if browser doesn&#39;t support local storage ---&gt;<br>&lt;div id=&quot;test&quot;&gt;&lt;/div&gt;</pre><h3>Creating the Javascript With a Local Storage Component</h3><p>First, I started with the “saveTitle()” function. I wrote an if statement to see if the browser supported local storage (else throw an error message). Then I created a variable to store the value of the title. I set that variable into local storage. Like so:</p><pre>var input = document.getElementById(&#39;title&#39;).value;<br>localStorage.setItem(&#39;title&#39;, input);</pre><p>Then, outside of the function, I told localStorage to get that ‘title’ item’:</p><pre>document.getElementById(&#39;title&#39;).value = localStorage.getItem(&#39;title&#39;);</pre><p>Here’s the full code for the “saveTitle()” section:</p><pre><em>//Save title w. local storage</em><br>function saveTitle() {<br>  <em>//Make sure local storage is supported by the browser<br></em>  if (typeof(Storage) !== &#39;undefined&#39;) {<br>    <br>    <em>//Get title value</em><br>    var input = document.getElementById(&#39;title&#39;).value;<br>    <br>    <em>//Save title to local Storage</em><br>    localStorage.setItem(&#39;title&#39;, input);<br>    document.getElementById(&#39;title&#39;).value = localStorage.getItem(&#39;title&#39;);</pre><pre>} else { <br>    <em>//Throw an error if browser doesn&#39;t support local storage</em><br>    document.getElementById(&#39;test&#39;).innerHTML(&#39;Sorry, your browser does not support Web Storage...&#39;)<br>  }</pre><pre>}<br><em>//Get the value of the title from local storage.</em><br>document.getElementById(&#39;title&#39;).value = localStorage.getItem(&#39;title&#39;)</pre><p>Afterwards, I repeated the same process for the ‘saveMessage()’ function. Instead using the value of the ‘message’ ID to save the body of the note. Here is the full code for that function:</p><pre><em>//Save note message</em><br>function saveMessage() {<br>  if (typeof(Storage) != &#39;undefined&#39;) {<br>    <em>//Get value of the message</em><br>    var messageInput = document.getElementById(&#39;message&#39;).value;<br>    <br>    <em>//Save the value in local storage.</em><br>    localStorage.setItem(&#39;message&#39;, messageInput);<br>    document.getElementById(&#39;message&#39;).value = localStorage.getItem(&#39;message&#39;)<br>    <br>    <br>  } else { <br><em>    //Throw an error if browser doesn&#39;t support local storage</em><br>    document.getElementById(&#39;test&#39;).innerHTML(&#39;Sorry, your browser does not support Web Storage...&#39;)<br>  }</pre><pre>}</pre><pre><em>//Get the value of the message from local storage</em><br>document.getElementById(&#39;message&#39;).value = localStorage.getItem(&#39;message&#39;)</pre><p>And voila! You now have the code to create a note app, and when the user refreshes the browser, the note will be saved to their local storage. Feel free to add in any CSS to fully customize the look and feel of the note.</p><h3>Here’s the Full Code on CodePen:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmirandalwashburn%2Fembed%2Fpreview%2FxxKdYzR%3Fheight%3D600%26slug-hash%3DxxKdYzR%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fmirandalwashburn%2Fpen%2FxxKdYzR&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F1798366.xxKdYzR.small.a97434b9-a55c-49bf-b62a-899039c230f7.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cf6753dabad7a7c47574b71ffa922a8/href">https://medium.com/media/2cf6753dabad7a7c47574b71ffa922a8/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14165975ba86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Toggle Dark Mode with Javascript & Local Storage]]></title>
            <link>https://medium.com/@mirandawashburn/toggle-dark-mode-with-javascript-local-storage-8a9376828279?source=rss-4adb653e1b0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a9376828279</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[jquery]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[dark-mode]]></category>
            <dc:creator><![CDATA[Miranda Washburn]]></dc:creator>
            <pubDate>Sun, 21 Apr 2019 18:19:26 GMT</pubDate>
            <atom:updated>2019-04-21T19:39:21.781Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*6SyVBxHCfxwGossZ8eK2rw.jpeg" /></figure><ol><li><strong>The first step is to set up the HTML.</strong></li></ol><p>I wrapped my HTML with the &lt;main&gt; tag but you could easily use the body tag. Then set up the markup for your toggle button. You’ll want to include an onclick method on your input to run the code to toggle the light/dark background.</p><pre>&lt;main id=&quot;main&quot;&gt;<br> &lt;p&gt; Click to toggle dark mode &lt;/p&gt;<br> &lt;label class=&quot;switch&quot;&gt;<br>  &lt;input type=&quot;checkbox&quot; onclick=&quot;darkLight()&quot; id=&quot;checkBox&quot; &gt;<br>  &lt;span class=&quot;slider&quot;&gt;&lt;/span&gt;<br> &lt;/label&gt;<br>&lt;/main&gt;</pre><p>2.<strong> Then set up the CSS for the background colors:</strong></p><p>I set up my main class to cover the entire viewport width and height (VH &amp; VW) and added flex styling to center the toggle button and text.</p><pre>main {<br>   height: 100vh;<br>   width: 100vw;<br>   transition: background 0.3s ease;<br>   display: flex;<br>   flex-direction: column;<br>   justify-content: center;<br>}</pre><pre>main p {<br>   align-self: center;<br>   font-family: sans-serif;<br>   transition: color 0.3s ease;<br>}</pre><p>Then set up your ‘dark’ class to have a dark background color and a light text color.</p><pre>/*TOGGLE COLORS*/</pre><pre>.dark {<br>   background: #545454;<br>   color: #efefef;<br>}</pre><p>Finally, create the styling for the toggle switch/button:</p><pre>*SWITCH*/<br>.switch {<br>   position: relative;<br>   display: inline-block;<br>   width: 60px;<br>   height: 34px;<br>   align-self: center;<br>}</pre><pre>.switch input {<br>   opacity: 0;<br>   width: 0;<br>   height: 0;<br>}</pre><pre>.slider {<br>   position: absolute;<br>   cursor: pointer;<br>   top: 0;<br>   left: 0;<br>   right: 0;<br>   bottom: 0;<br>   background-color: #ccc;<br>   -webkit-transition: 0.4s;<br>   transition: 0.4s;<br>}</pre><pre>.slider:before {<br>   position: absolute;<br>   content: &quot;&quot;;<br>   height: 26px;<br>   width: 26px;<br>   left: 4px;<br>   bottom: 4px;<br>   background-color: white;<br>   -webkit-transition: 0.4s;<br>   transition: 0.4s;<br>}</pre><pre>input:checked + .slider {<br>   background-color: #2196f3;<br>}</pre><pre>input:checked + .slider:before {<br>   -webkit-transform: translateX(26px);<br>   -ms-transform: translateX(26px);<br>   transform: translateX(26px);<br>}</pre><pre>/* Rounded sliders */<br>.slider {<br>   border-radius: 30px;<br>}</pre><pre>.slider:before {<br>   border-radius: 50%;<br>}</pre><p>3<strong>. Now the fun part! I used JQuery for this, so make sure you include the src script in your code.</strong></p><p>First set up your local storage:</p><pre>$(‘#main’).toggleClass(localStorage.toggled);</pre><p>Then create the code for the darkLight() onClick event. I created an if/else statement to toggle the dark class and save it to the local storage.</p><pre>function darkLight() {<br>   if (localStorage.toggled != &#39;dark&#39;) {<br>      $(&#39;#main, p&#39;).toggleClass(&#39;dark&#39;, true);<br>      localStorage.toggled = &quot;dark&quot;;<br>   } else {<br>      $(&#39;#main, p&#39;).toggleClass(&#39;dark&#39;, false);<br>      localStorage.toggled = &quot;&quot;;<br>   }<br>}</pre><p>Lastly, I added the ‘checked’ property to the toggle button, if the ‘main’ class also has the dark class attached to it:</p><pre>if ($(&#39;main&#39;).hasClass(&#39;dark&#39;)) {<br>      $( &#39;#checkBox&#39; ).prop( &quot;checked&quot;, true )<br>} else {<br>      $( &#39;#checkBox&#39; ).prop( &quot;checked&quot;, false )<br>}</pre><p>And voila! You now have the code to toggle a dark/light background, and when the user refreshes the browser, the background color will be saved to their local storage.</p><p>Here’s the full code on CodePen:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmirandalwashburn%2Fembed%2Fpreview%2FwZmZLz%3Fheight%3D600%26slug-hash%3DwZmZLz%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fmirandalwashburn%2Fpen%2FwZmZLz%3Feditors%3D0010&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F1798366.wZmZLz.small.1074f594-04ff-4a94-a2a8-9f7f5f9f8d94.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/942d64a3927d218ad1ade5f6153885b5/href">https://medium.com/media/942d64a3927d218ad1ade5f6153885b5/href</a></iframe><p>This is my first story on Medium, so feel free to send any feedback!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a9376828279" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>