What I want to do:
I want to add rules and modify existing rules inside of a <style> tag with javascript/jQuery.
Why I want to do it:
I'm basically building a color scheme editor and when the user changes a value in the form, I want to update the CSS to reflect this change.
What I've Tried:
Replacing the entire <style> tag with CSS generated by a JS function. This works but seems like a lot of processing for a very small change.
Also I can create container <div>s that contain specific CSS classes and simply find/replace their HTML. Exmaple below:
<div id="button_background_cont">
<style type="text/css">.buttons {background-color:#333333;}</style>
</div>
<div id="button_color_cont">
<style type="text/css">.buttons {color:#ffffff;}</style>
</div>
These both work... but are really clunky and I don't particularly like them.
Example Of What I Need To Do:
<style type="text/css" id="color_scheme">
.buttons {background:#333333; color:#ffffff;}
</style>
<input name="button_background" id="button_background" value="#333333" />
<input name="button_color" id="button_color" value="#ffffff" />
Change The form elements and make it the following
<style type="text/css" id="color_scheme">
.buttons {background:#ff0000; color:#333333;}
</style>
<input name="button_background" id="button_background" value="#ff0000" />
<input name="button_color" id="button_color" value="#333333" />
Any ideas?