In firefox, how can I modify an existing CSS rule

In firefox, I have the following snippet in my .css file

tree (negative){  font-size: 120%; color: green;}

Using javascript how to change a rule to set the color to red?

Note:
I do not want to change the item.
I want to change the rule. Please do not respond with something like

...

element.style.color = 'red';

+3
source share
11 answers

What you are looking for is a property document.styleSheetswith which you can access and manage your CSS rules. Most browsers have this property, but the IE interface is slightly different for IE.

, FF enter:

javascript:alert(document.styleSheets[0].cssRules[1].cssText)

"body { line-height: 1; }". /, .

, (-): http://code.google.com/p/sheetup/

+3
function changeCSSRule (stylesheetID, selectorName, replacementRules) {
    var i, theStylesheet = document.getElementById(stylesheetID).sheet,
    thecss = (theStylesheet.cssRules) ? theStylesheet.cssRules : theStylesheet.rules;
    for(i=0; i < thecss.length; i++){
        if(thecss[i].selectorText == selectorName) {
            thecss[i].style.cssText = replacementRules;
        }
    }
};
+2

CSS CSS ( DOM Level 2 Style). , " ()" , .

+1

HTML tree, , tree id class .

DOM id:

var tree = document.getElementById("tree");

tree DOM, :

tree.style.color = "red";

css javascript.

0

, /. , .tree, CSS. - jQuery ( ):

$('.tree').each(function() { this.style.color = "red"; });

CSS:

$('.tree').css('color', 'red');

( , , JS. $(...) - jQuery .tree. jQuery, .)

tree , ( ), getElementById . .

0

for( var i in document.getElementsByTagName("tree") ){
   document.getElementsByTagName("tree")[i].style.color = "red";
}
0

, , , . - , CSS, .

, : jQuery.Rule

, , , . , , , , jQ, .

: , . , <style> . , JS.

0

Firebug CSS .

0

CSS- , - . .

, AJAX CSS .

0

" , , ".

, , ( "ajax" ) , , , ?

/ Firefox ?

0

, .

. / .

: cookie javascript.

: , - .

, , element.style.color =. , .

0

All Articles