Keep formatting on dynamically fixed <thead>

Keep formatting on dynamically fixed <thead>

Hi guys!

I've got following problem:
I am dynamically fixing the current thead to the top (or rather adding and removing it from the DOM). 
Here's the code:
  1. function fixedThead(elem){
  2.     $(elem).each(function(){
  3.     var el = elem,
  4.         theight = $(el).parent().outerHeight(),
  5.         twidth = $(el).parent().outerWidth(),
  6.      offset = $(el).offset(),
  7.      toph  = $(".navbar").outerHeight();
  8. clone = $(el).clone().addClass("headerFixed").css({
  9. width: twidth
  10. });

  11. $(window).scroll(function(){
  12.      var scrollTop = $(window).scrollTop();
  13. if ((scrollTop >= offset.top + theight) || (scrollTop < offset.top)) {
  14.      $(clone).remove();
  15.      } else if ((scrollTop < offset.top + theight) && (scrollTop > offset.top)){
  16.      $(el).parent().prepend(clone);
  17.      }
  18.    });  
  19. });
  20. }
That works perfectly.

On my page I am also using a selfwritten hashchange AJAX function. And in the Ajax Request I am just calling the fixedThead() function with a property of a settings object.
So if I click on a link (ergo hashchange), the script will empty the var clone, buuut if i console.log(clone) then clone is defined twice. --> So for every click i make on the page a new clone is added, though ALL clones have the exact same value.

My question: if i completely empty an object (using a for-in-loop), can i somehow delete it or what can I do?

thanks in advance!


Greetings, Internerd