String.prototype.cssObj( styleObject[Object][optional] )String.prototype.cssObj= function( styleObj ){ styleObj = styleObj || {};
var pairs=this.replace( /(^\s*)|(;\s*$)/g, '' ).split( /\s*;\s*/ ),selector,propAndVal,i=pairs.length;
while( i-- ){ propAndVal= pairs[i].split( /\s*:\s*/ );
selector=propAndVal[0] ;if( selector.match(/-/) ){ selector=selector.cc() }
styleObj[ selector ]= propAndVal[1].toLowerCase()}; return styleObj;
};
String.prototype.camelCase= String.prototype.cc = function(){
return this.replace(/-\D/gi, function(match){return match.charAt(match.length - 1).toUpperCase()} );
};This code fits in wonderfully with many of the dom creation functions around, like the one on here. Example:
var s={ backgroundColor:'#f00',position:'absolute', width:'50px', height:'50px'};
'padding:5px; border-width:4px; border-style:solid; border-color:#333'.cssObj(s);