title: Strange result in adding event to a dynamically created element
body: <p>This code will run (at least in Firefox ) and will create and attach the onmouseover event handler on the three elements designated to have a submenu by having the name preceded by an _.  It does not add the handler to those which should not have it.</p>
  
  <p>If I trace through in Firebug, everything appears to be working fine; that is the handler is attached with the correct id and navtitle.</p>
  
  <p>In the browser, the correct elements have a mouseover event which fires.
  HOWEVER, the parameters passed to that event handler in EVERY case are '6' and 'Other' despite the fact that no event handler is even attached to 'Other'.  I think I've scoped everything correctly so I do not understand why this is happening.</p>
  
  <p>What am I missing here?</p>
  
  <p>Thanks!</p>
  
  <p>// Parent element to which I will add child elements</p>
  
  <pre><code>var navdiv = document.getElementById('nav') 
  
  var navarray = ['','Home', '_Books', '_Pictures', '_Characters','Other']
  </code></pre>
  
  <p>// Horizontal Menu</p>
  
  <pre><code>var nnav = navarray.length
  
  for (var ii = 1; ii &lt; nnav; ii++) 
  {
  
  // get title and determine whether it has a submenu
  var subflag = false
  var navtitle = navarray[ii]
  var firstchar = navtitle[0]
  if (firstchar == '_') 
  {
      navtitle = navtitle.substring(1, navtitle.length - 1)
      navtitle += '*'
      subflag = true
  
  }
  
  
  // Create Div
  
  var naventry = document.createElement('div')
  var navid = 'nav' + navarray[ii]
  naventry.setAttribute('id', navid)
  naventry.setAttribute('class', 'navitem')
  // Create Link
  var lnk = document.createElement('a')
  lnk.setAttribute('href', navarray[ii] + '.html')
  if (subflag) // will have a submenu
  {
      lnk.onmouseover = function () { dropmenu(ii, navtitle) }
  }
  
  var txtnode = document.createTextNode(navtitle)
  lnk.appendChild(txtnode)
  
  naventry.appendChild(lnk)
  navdiv.appendChild(naventry)
  lnk = null
  }
  
  function dropmenu(which, ntitle) 
  {
  alert('In drop menu: Id = ' + which + '  ' + ntitle)
  return false;
  }
  </code></pre>