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:
- function fixedThead(elem){
- $(elem).each(function(){
- var el = elem,
- theight = $(el).parent().outerHeight(),
- twidth = $(el).parent().outerWidth(),
- offset = $(el).offset(),
- toph = $(".navbar").outerHeight();
- clone = $(el).clone().addClass("headerFixed").css({
- width: twidth
- });
- $(window).scroll(function(){
- var scrollTop = $(window).scrollTop();
- if ((scrollTop >= offset.top + theight) || (scrollTop < offset.top)) {
- $(clone).remove();
- } else if ((scrollTop < offset.top + theight) && (scrollTop > offset.top)){
- $(el).parent().prepend(clone);
- }
- });
- });
- }
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