title: Javascript: IE event.preventDefault is null or not an object
body: <p>My code works fine in FF/Chrome/Everything except IE(failed in both 7/8, didn't bother going furthur down). Due to restrictions, I cannot use jQuery and am hard-coding the Javascript. The issue is with IE, I am getting "preventDefault is null or not an object". Hoping one of you has the answer, and here's relevant code:</p>
  
  <p>AddEvent Method:  </p>
  
  <pre><code>function addEvent( obj, type, fn ) {  
    if ( obj.attachEvent ) {  
      obj['e'+type+fn] = fn;  
      obj[type+fn] = function(){obj['e'+type+fn]( window.event );}  
      obj.attachEvent( 'on'+type, obj[type+fn] );  
    } else  
      obj.addEventListener( type, fn, false );  
  };
  </code></pre>
  
  <p>Event handler throwing error:</p>
  
  <pre><code>function mousedown(e){  
    if(e.preventDefault){  
      e.preventDefault();  
    } else {  
      e.returnValue = false;  
      e.cancelBubble=true;  
    }
    //Processing   
  };
  </code></pre>
  
  <p>Also DOCTYPE and charset are both set on the calling HTML page. Any ideas would be appreciated. The error is thrown in the if statement for the mousedown method.</p>
  
  <p>EDIT:</p>
  
  <p>Due to the fact that grabbing window.event did "fix" the main issue, I discovered the problem was a different section of code. Basically I am adding a  element ontop of a pre-placed element, and then registering mousedown/mousemove events to that div. When firing the event on the <code>&lt;div&gt;</code>, THAT'S where the error is thrown.</p>
  
  <p>Could this be something due to the fact that I have events registered to 2 </p>
  
  <pre><code>rect = document.createElement('div');  
  rect.className='square';  
  rect.id='chooser_rectangle';  
  rect.style.left=initx+'px';  
  rect.style.top=inity+'px';  
  
  addEvent(rect,"mousemove",mousemove);  
  addEvent(rect,"mousedown",mousedown);  
  </code></pre>