The title should sum it up pretty well…
In this fiddle, when you press the “switch” text, the jQuery creates a duplicate header in place of the original. The only thing wrong (for now) is that the input field moves to the right.
How can I stop this?
jQuery code for reference (Stack Overflow doesn’t like no code):
function duplicate(){
var w = $('#old').find('tr:last').find('td').map(function(index){
return $(this).outerWidth();
}).get();
var newth = $('#oldHead').find('th').map(function(){
return $(this).text();
}).get();
for (var i = 0; i < newth.length; i++){
if (i<1){
$('<span>' + newth[i] + '</span>').appendTo('#new');
} else {
$('<span style="width:' + (w[i] - 20) + 'px">' + newth[i] + '</span>').appendTo('#new > #newfloat');
}
}
$('#oldHead').find('tr').remove();
$('#oldBody').find('tr:first').find('td').each(function(index){
$(this).css({'width': w[index] + 'px'});
});
}
$('#switch').click(function(){
duplicate();
});
The issue was resolved with a
min-widthproperty on the offendingtdtags – as well as removing the left and right padding.http://jsfiddle.net/verism/s7VBu/
If anyone knows of any pitfalls this may invoke, I’d be interested to hear.