Add stylesheet via Javascript | 2012-01-15

Technology Blog » Web Development

Create variable of CSS attributes:

var css_attributes='div #postform {
    float:left; border: 1px outset;cursor: hand;
}';

Append in DOM:

var stylesheet = document.createElement('style');
stylesheet.type = 'text/css';
stylesheet.appendChild(
  document.createTextNode(css_attributes)
);