title: Get ID of dynamically-created DIV not working in FireFox
body: <p>I've tried everything to find this answer and it's now 1:00 in the morning and I have to go to bed and give up :( before my wife serves me with our second divorce ! :)</p>
  
  <p>My problem in short is this, I use google API's to (localsearch,imagesearch and websearch) to locate various strings that I incorporate into my site. They are loaded into a dynamic DIV and each set of results are given a div with an integer relating to it's number. For example,</p>
  
  <pre><code>for (var i = 0; i &lt; localSearch.results.length; i++) {
  
    // Create HTML elements for search results
  
  
    var letsseetitle = localSearch.results[i].titleNoFormatting;
      letsseestreet = localSearch.results[i].streetAddress;
      var letsseecity = localSearch.results[i].city;
      var letsseeregion = localSearch.results[i].region;
      var letsseecountr = localSearch.results[i].country;
      var letsseestaticmapurl = localSearch.results[i].staticMapUrl;
      var latresult = localSearch.results[i].lat;
      var lng = localSearch.results[i].lng;
  
       dv = document.createElement('div'); // create dynamically div tag
          var attrname = "selectionbox" + i;
              dv.setAttribute('id',attrname);       //give id to it
                  var goFetchThis = letsseetitle + " " + letsseestreet + " " + letsseeregion + " " + letsseecountr;
  
                      dv.style.border="solid";    
                      dv.style.padding="10px";
                      dv.style.backgroundColor="#80C4FF";
                      dv.title="Click to review this company.";
  
                  dv.innerHTML= letsseetitle + "&lt;BR&gt;" + letsseestreet + "&lt;BR&gt;" + letsseecity + "&lt;BR&gt;" + letsseeregion + "&lt;BR&gt;"  + letsseecountr + "&lt;BR&gt;";
  
                  //var el = document.getElementById(attrname);
                      LoopIn = i; 
  
                      // attach event onmouseclick to the created div tag
                  if(isIE){
                      dv.onclick = new Function("SelectThis(attrname, attrname)");
                          }
                  else{
                          dv.setAttribute("onclick", "SelectThis()");
                              }
                      document.getElementById("foundresultsdiv").appendChild( dv );
  
  
  
  
  
  
  
  
  
          }
  </code></pre>
  
  <p>Now the problem is this. In both chrome, ie, safari and others I have no problem with the on-click component. IE, when the user clicks on one of the dynamically created divs, my script strips the content and loads them up into the form ready for the user to submit.</p>
  
  <p>The script that does this follows;</p>
  
  <pre><code>function SelectThis(e) {
  var targ;
  
  
  
  
  
  
      if (!e) var e = window.event;
  
          if (!e) var e = elTags[e].getAttribute("name");
                  if (e.target) targ = e.target;
                      else if (e.srcElement) targ = e.srcElement;
  
      if (!e) var e = window.event;
      if (e.target) targ = e.target;
  
      else if (e.srcElement) targ = e.srcElement;
      if (targ.nodeType == 3) // defeat Safari bug
              targ = targ.parentNode;
                  theId=targ.id
  
  
  
  var TheStuffInside = document.getElementById(theId).innerHTML;
  var linebyline = TheStuffInside.split("&lt;br&gt;");
  
  
  var searchname = document.getElementById('searchname')
      searchname.value = linebyline[0];
  
  var stAddress = document.getElementById('stadd')
      stAddress.value = linebyline[1];
  
  var suburb = document.getElementById('suburb')
      suburb.value = linebyline[2];
  
  var stateLocal = document.getElementById('statelocal')
      stateLocal.value = linebyline[3];
  
  var country = document.getElementById('country')
      country.value = linebyline[4];
  
  }
  </code></pre>
  
  <p>Now I can't brag here because I didn't write this script at all, and in the main it works well. EXCEPT in firefox. When I click on one of the dynamic divs in firefox NOTHING happens at all. In fact, the element returns an undefined result. I've tried heaps of variations from changing the code to adding event listeners on the on-load and I've had NO LUCK at all. </p>
  
  <p>Any advice here would be greatly appreciated. Who knows - you may even save my marriage !:)</p>
  
  <p>By the way, the // beat safari bug is technically incorrect but I didn't write it ok ! :)</p>
  
  <p>Any questions please let me know.</p>