When iterating over some table cell data, I construct an array of whatever's found. The first iteration simply wraps the found text in some <span>
tags, whilst the subsequent ones add a bunch of other styles, as below:
var array = $('table').find('th').map(function(i){
if (i===0){
// This bit's OK
return '<span>' + $(this).text() + '</span>';
} else {
// This just looks horrible
return '<span style="width:' + $(this).outerWidth() + 'px; display:inline-block; position:absolute; right:' + w[i-1] + 'px">' + $(this).text() + '</span>';
}
}).get();
It all works fine, but it's hideous - and I think I've seen a much more elegant way of constructing HTML elements, with styles, somewhere before.
Can anyone suggest a more "maintenance-friendly" way of writing the else
statement?
EDIT: Using CSS classes isn't really a solution, as the code applies values based on other calculations.