Skip to content

Instantly share code, notes, and snippets.

@nemtsov
Created September 20, 2019 17:04
Show Gist options
  • Save nemtsov/39f6bfaa235800892f916dafdd57f78f to your computer and use it in GitHub Desktop.
Save nemtsov/39f6bfaa235800892f916dafdd57f78f to your computer and use it in GitHub Desktop.
let variablesStyles: { [key: string]: HTMLStyleElement } = {};
function updateCssStyle(id: string, styleString: string): void {
const newStyle = styleString;
if (!variablesStyles[id]) {
variablesStyles[id] = document.createElement('style');
document.head.appendChild(variablesStyles[id]);
}
variablesStyles[id].innerHTML = newStyle;
}
export function updateCssClass(className: string, styleString: string): void {
updateCssStyle(
className,
`
.${className} {
${styleString}
}
`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment