Skip to main content
small corrections, removed intro, shorter title
Source Link
unor
  • 7.7k
  • 5
  • 39
  • 100

Are there any jquery plugins jQuery plugin for manipulating stylesheets?

Question moved from Stack Overflow since it's apparently offtopic there.

It appears people misunderstand the request. I'm perfectly aware that jqueryjQuery has css() method which allows me to modify the style specified elements. However I want to modify rules within a stylesheet on the go. It has some legit uses which the css() method cannot replace.

Something like:

<style id="dyn-style">
    p{ color:black; }
</style>
<p>TEST</p>
<script>
    $('#dyn-style').getCssRule('p').alterRule('color', 'red');
</script>

Which then changes the contentscontent of the stylestyle element to this:

<style id="dyn-style">
    p{ color:red; }
</style>

I searched a bit, but only found this solution. From what I understand, it only adds new stylestyle elements (with defined styles) rather than alter existing ones.

I'm tempted to write a plugin ofon my own, but it would be pointless to do so if one exists already.

Are there any jquery plugins for manipulating stylesheets?

Question moved from Stack Overflow since it's apparently offtopic there.

It appears people misunderstand the request. I'm perfectly aware that jquery has css() method which allows me to modify the style specified elements. However I want to modify rules within a stylesheet on the go. It has some legit uses which css() method cannot replace.

Something like:

<style id="dyn-style">
    p{ color:black; }
</style>
<p>TEST</p>
<script>
    $('#dyn-style').getCssRule('p').alterRule('color', 'red');
</script>

Which then changes the contents of the style to this:

<style id="dyn-style">
    p{ color:red; }
</style>

I searched a bit, but only found this. From what I understand it only adds new style elements (with defined styles) rather than alter existing ones.

I'm tempted to write a plugin of my own, but it would be pointless to do so if one exists already.

jQuery plugin for manipulating stylesheets

I'm perfectly aware that jQuery has css() method which allows me to modify the style specified elements. However I want to modify rules within a stylesheet on the go. It has some legit uses which the css() method cannot replace.

Something like:

<style id="dyn-style">
    p{ color:black; }
</style>
<p>TEST</p>
<script>
    $('#dyn-style').getCssRule('p').alterRule('color', 'red');
</script>

Which then changes the content of the style element to this:

<style id="dyn-style">
    p{ color:red; }
</style>

I searched a bit, but only found this solution. From what I understand, it only adds new style elements (with defined styles) rather than alter existing ones.

I'm tempted to write a plugin on my own, but it would be pointless to do so if one exists already.

Source Link
jahu
  • 185
  • 9

Are there any jquery plugins for manipulating stylesheets?

Question moved from Stack Overflow since it's apparently offtopic there.

It appears people misunderstand the request. I'm perfectly aware that jquery has css() method which allows me to modify the style specified elements. However I want to modify rules within a stylesheet on the go. It has some legit uses which css() method cannot replace.

Something like:

<style id="dyn-style">
    p{ color:black; }
</style>
<p>TEST</p>
<script>
    $('#dyn-style').getCssRule('p').alterRule('color', 'red');
</script>

Which then changes the contents of the style to this:

<style id="dyn-style">
    p{ color:red; }
</style>

I searched a bit, but only found this. From what I understand it only adds new style elements (with defined styles) rather than alter existing ones.

I'm tempted to write a plugin of my own, but it would be pointless to do so if one exists already.