add an event to an element
<p>I am a new learner of javascript, the following code is from the javascript definitive guide.</p>

<pre><code>function addEvent(elem, evtType, func)
{
   if (elem &amp;&amp; typeof(elem) == "object")
   {

      if (elem.addEventListener)
      {
         elem.addEventListener(evtType, func, false);
      }

      else
      {
         elem["on" + evtType] = func;
      }
   }
}
</code></pre>

<p>why it add </p>

<pre><code>  if (elem.addEventListener)
  {
     elem.addEventListener(evtType, func, false);
  }
</code></pre>

<p>but the <code>window.onload</code> works ok under every browsers. the following is my test example.</p>

<pre><code>&lt;script type="text/javascript"&gt;
         window.onload=myFuntion();
        function myFuntion(){
            alert("test");
        }
    &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;

    &lt;h1&gt; testtste &lt;/h1&gt;
&lt;/body&gt;
</code></pre>

<p>it works ok under IE ff.</p>
