title: How to add class cookie by javascript?
body: <p>i don't want to change class after page loaded. How to add class cookie in my project.</p>
  
  <p><strong>HTML</strong>
      Red
      Green</p>
  
  <pre><code>&lt;div class="red"&gt;Testing Text1&lt;/div&gt;
  &lt;div class="red"&gt;Testing Text2&lt;/div&gt;
  </code></pre>
  
  <p><strong>CSS</strong></p>
  
  <pre><code>.red{
      color: red;
      font-weight: bold;
  }
  .green {
      color: green;
      font-weight: bold;
  }`
  </code></pre>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>  function changeClass(value) {
       var color1 = 'red';
       var color2 = 'green';
       if (value == 2) {
           color1 = 'green';
           color2 = 'red';
       };
  
       var elems = document.getElementsByClassName(color1);
       var i = elems.length;
       while (i--) {
           var item = elems[i];
           if (hasClass(item, color1)) {
               removeClass(item, color1);
               addClass(item, color2);
           }
       };
       return false;
   };
  
   function hasClass(ele, cls) {
       return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
   }
  
   function addClass(ele, cls) {
       if (!hasClass(ele, cls)) ele.className += " " + cls;
   }
  
   function removeClass(ele, cls) {
       if (hasClass(ele, cls)) {
           var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
           ele.className = ele.className.replace(reg, ' ');
       }
   }
  </code></pre>