Form file input element breaks while trying to reset using replaceWith

Form file input element breaks while trying to reset using replaceWith

I'm trying to write a function that overrides the default browser functionality for a input file element, but somewhere, I'm losing a connection to my input box and after about 10 hours of debugging, I give up.

I have the following function that takes the following arguments, all jQuery objects:

ele_input : the file input box that has 0 opacity (.5 for testing purposes)
ele_trigger : the UI button that triggers the ele_input box to show, making it able to receive clicks
ele_text : a text input box that acts as a label, displaying the selected file name
ele_clear : the UI button that triggers the resetting of the input file box

  1. function FileInputActivate(ele_input, ele_trigger, ele_text, ele_clear)
  2. {
  3. ele_input.hide(); // hide input element

  4. // Once a file is selected, ele_text (a label) is set to reflect the chosen file
  5. ele_input.change(
  6. function()
  7. {
  8. ele_text.val($(this).val());
  9. }
  10. );

  11. // On mouse over trigger
  12. ele_trigger.mouseover(
  13. function()
  14. {
  15. ele_input.show(); // show input element
  16. console.log(ele_input.is(':visible'));
  17. }
  18. );

  19. ele_clear.click(
  20. function()
  21. {
  22. ele_input.hide();
  23. ele_input.replaceWith(ele_input.clone(true)); // reloads file input, which acts as a clearing mechanism, which does clear correctly. is this breaking it?
  24. ele_text.val(''); // clear label text
  25. console.log(ele_input.val()); // displays as empty string, as it should
  26. }
  27. );
  28. }

For the first execution, everything works as it's supposed to, but as soon as the box is reset, ele_input no longer appears when the trigger receives mouseover. It's still an object, and using the same selector, gives an element, but I don't think it's the same one.

The line:
  1. console.log(ele_input.is(':visible'));
no longer returns TRUE, even though the preceding line explicitly calls the show() method.

Any help is greatly appreciated.