Merging nested tables into a single table
Suspicious code

The variable insideText seems to be used before it's defined.
Is that a global variable? Avoid global variables as much as possible.



This else block seems pointless:


else {
    var insideText = channelTableHeaders.text();
}





Something's suspicious here:


$('table#' + newTableName).html($('&lt;thead /&gt;'));



Note that ids must be unique in the document. So the table prefix there is redundant.

Readability

For better readability, put spaces around operators, for example instead of this;


var firstRow = $('&lt;tr&gt;&lt;th&gt;'+newTableName+'&lt;/th&gt;&lt;/tr&gt;');
$('#'+oldTableName+' .budget-inner-table').each(function() {



Get into the habit to write like this:

var firstRow = $('&lt;tr&gt;&lt;th&gt;' + newTableName + '&lt;/th&gt;&lt;/tr&gt;');
$('#' + oldTableName + ' .budget-inner-table').each(function() {




The ternary operator can be very useful sometimes.
But this expression is too complex and hard to read:


className = ((insideText.indexOf('-') &gt; 0) ? /- (.*)/.exec(insideText)[1]: insideText.replace(/ /g, '-')).toLowerCase();



It would be better to expand this to its equivalent using if-else:

if (insideText.indexOf('-') &gt; 0) {
    className = /- (.*)/.exec(insideText)[1];
} else {
    className = insideText.replace(/ /g, '-').toLowerCase();
}


Helper methods

You are using this kind of code in at least two places:


... = insideText.replace(/ /g, '-').toLowerCase();
... = headerText.replace(/ /g, '-').toLowerCase()



It would be good to introduce a helper function for this, for example:

function slugify(text) {
    return text.replace(/ /g, '-').toLowerCase();
}

... = slugify(insideText);
... = slugify(headerText);


Misc

Code like this can be simplified:


if (condition) {
    return;
} else {
    // do something
}



Like this:

if (condition) {
    return;
}

// do something