title: Getting/setting style of element when style is defined in id/class css?
body: <p>I might be missing something easy here, but I'm trying to get/set the background color of a div, but only if the background color is already set (whether it be from class/id, or style attribute, etc.).</p>
  
  <p>I've tried using <code>.style.backgroundColor</code>, but all it returns is an empty string (I think because the attribute is defined in the class/id, not the element style itself). <a href="https://jsfiddle.net/o0v268fz/2/" rel="nofollow">JSFiddle</a> to show what I mean.</p>
  
  <p>I can't use jQuery, and I also can't just select the attribute of the class/id itself because I'm doing this with a large collection of (potentially unrelated) elements.</p>
  
  <p>In the end, the goal is to have something like this:</p>
  
  <pre><code>var allElements = document.getElementsByTagName("*");
  for (var i = 0; i &lt; allElements.length; i++) {
      if (allElements[i].style.backgroundColor != '') {
          allElements[i].style.backgroundColor = 'blue';
      }
  }
  </code></pre>
  
  <p>Thanks!</p>