title: Uncaught TypeError: Cannot set property 'background' of undefined
body: <p>I am trying to load css background images on page load but I am getting this error   </p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot set property 'background' of undefined</p>
  </blockquote>
  
  <pre><code>function loadBG() {
      document.getElementsByClassName("img-icon-invite").style.background = "url('&lt;?php echo Yii::app()-&gt;theme-&gt;baseUrl; ?&gt;/style/home/images/firstProPopup-sprite-new-white.png')";
      document.getElementsByClassName("img-icon-verified").style.background = "url('http://dev1.venturepact.com/themes/adminre/style/home/images/firstProPopup-sprite-new-white.png')";
  }
  
  window.onload = loadBG();
  </code></pre>