title: How to clone an element and not fire events in Chrome?
body: <p>I am attempting to clone an input element of type="file". In this input element there is an onchange event. The clone method is called in the function that is called from the onchange event. </p>
  
  <p>The problem I am having is that when I clone the file upload input, the onchange event is fired again. This only happens in Chrome, but works as intended in IE. </p>
  
  <pre><code>&lt;input type="file" id="fileUpLoad" onchange="doFunction();" /&gt;
  
  doFunction = function() {
      var oldEl = $('#fileUpLoad');
      var newEl = $(oldEl).clone();
      $(oldEl).attr('id','fileUpLoadOLD');
      $(oldEl).before(newEl);
  }
  </code></pre>
  
  <p>I have created a fiddle duplicating this issue. <a href="http://jsfiddle.net/sanpopo/2yofue6e/" rel="nofollow">Here is the fiddle.</a> </p>
  
  <p>How can I clone this file upload input without firing the onchange event again and again? I am using jQuery 1.7.1. This is actually a simplified a snippet from <a href="https://github.com/kunashir/pricemap/blob/master/price_map/public/AjaxFileUploaderV2.1/ajaxfileupload.js" rel="nofollow">ajaxfileuploader.js</a>:</p>
  
  <pre><code>var oldElement = jQuery('#' + fileElementId);
  var newElement = jQuery(oldElement).clone();
  jQuery(oldElement).attr('id', fileId);
  jQuery(oldElement).before(newElement);
  jQuery(oldElement).appendTo(form);
  </code></pre>
  
  <p>UPDATE: fiddle <a href="http://jsfiddle.net/sanpopo/pefbcjkp/" rel="nofollow">I think this is accomplishing what I need</a> based on @MichaelAngstadt answer. Still testing though.</p>
  
  <p>This is what seems to be working for me in the ajaxfileuploader.js extension:</p>
  
  <pre><code>    var oldElement = jQuery('#' + fileElementId);
      var oldElEvents = oldElement.data("events");
      var newElement = jQuery(oldElement).attr('id', fileId).data("events", null).clone();
      jQuery(oldElement).attr('id', fileElementId).before(newElement);
      jQuery(oldElement).data("events", oldElEvents);
      jQuery(newElement).appendTo(form);
  </code></pre>