title: How refresh the style of an HTML element after changing it using Javascript?
body: <p>I have an HTML page containing XML.     Using Javascript, the XML attributes can be changed when the user clicks a button.    (So far, everything works)</p>
  
  <p>However, the attribute that is changed is used in the linked CSS to determine the background color of the element.    When the attribute value is changed, the style is not refreshed, so the color doesn't change.</p>
  
  <p>I can alter the javascript to also change the color, but that would involve hardcoding the color, and partially defeat the point of using CSS.</p>
  
  <p>So, it seems to me, I need to do one of two things, and I can't figure out how to do either:</p>
  
  <ul>
  <li>read the color from the CSS, and then assign it using javascript</li>
  <li>somehow use javascript to have the CSS re-applied to the document.</li>
  </ul>
  
  <p>Which approach is better?       I assume the 2nd is easier, unless there is a side-effect I haven't thought of.      And, whichever approach is better, HOW TO DO IT?</p>
  
  <p>My CSS contains:</p>
  
  <pre><code>*[cleared=true] {
  background:lightgrey;
  }
  </code></pre>
  
  <p>My XML looks like this:</p>
  
  <pre><code>&lt;Transfer ID="31266" Date="2015-04-14" Cleared="false"&gt;
      &lt;AccountCharge Account="Unplus"&gt;-826.20&lt;/AccountCharge&gt;
      &lt;AccountCharge Account="Amex"&gt;826.20&lt;/AccountCharge&gt;
      &lt;TransactionID&gt;1504140662984782&lt;/TransactionID&gt;
  &lt;/Transfer&gt;
  </code></pre>
  
  <p>My Javascript is:</p>
  
  <p></p>
  
  <pre><code>function Reconcile(Element_ID){
  try {
      var c=document.getElementById(Element_ID);
      c.setAttribute('Cleared','True');
      }
  catch(e) {
      alert(e.description);
      }
  }
  </code></pre>
  
  <p></p>
  
  <p>I have tried changing the script from modifying 'Cleared' to 'Date', and I can see the date change.       The 'Cleared' attribute is not displayed directly by the CSS, but is used to set the formatting of other elements and/or attributes.</p>
  
  <p>Changing the value of 'Cleared' before the page is loaded has the effect I expect - the CSS causes the formatting I expect.      However, after the page is loaded, when the javascript changes the value of 'Cleared', no visible change in formatting takes place.</p>