title: Javascript - getting the background color of the hovered element
body: <p>I'm currently making a google chrome extension and am using this javascript to change dynamically the background color of the hovered element:</p>
  
  <pre><code>var bindEvent = function(elem ,evt,cb) {
      //see if the addEventListener function exists on the element
      if ( elem.addEventListener ) {
          elem.addEventListener(evt,cb,false);
      //if addEventListener is not present, see if this is an IE browser
      } else if ( elem.attachEvent ) {
          //prefix the event type with "on"
          elem.attachEvent('on' + evt, function(){
              /* use call to simulate addEventListener
               * This will make sure the callback gets the element for "this"
               * and will ensure the function's first argument is the event object
               */
               cb.call(event.srcElement,event);
          });
      }
  };
  
  
  bindEvent(document,'mouseover', function(event) 
  { var target = event.target || event.srcElement;
      /* getting target.style.background and inversing it */
  });
  
  bindEvent(document,'mouseout', function(event) 
  { var target = event.target || event.srcElement;
      /* getting target.style.background and inversing it */
  });
  </code></pre>
  
  <p>and when used with static values, like <code>target.style.background = #FFFFFF;</code> when the cursor hover an element and <code>target.style.background = #00000;</code> when the cursor leave the element, it works perfectly. However, when I try to get the value of <code>target.style.background</code> or even <code>target.style.backgroundColor</code>, I always get <code>rgb(255,255,255)</code>, no matter what the background color of the element is. </p>
  
  <p>I know how to convert rgb to hexa and how to inverse it, but if I can't get the initial value of the background, it's useless.</p>
  
  <p>So, my question is: why do <code>var foo = target.style.backgroundColor;</code> always return <code>rgb(255, 255, 255)</code> and how do I get the correct value?</p>
  
  <p>Additional notes: the extension will be ported to other browsers later, so a cross-browser solution would be nice if it is possible.</p>