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';
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.
document.styleSheets
, FF enter:
javascript:alert(document.styleSheets[0].cssRules[1].cssText)
"body { line-height: 1; }". /, .
"body { line-height: 1; }"
, (-): http://code.google.com/p/sheetup/
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; } } };
CSS CSS ( DOM Level 2 Style). , " ()" , .
HTML tree, , tree id class .
tree
id
class
DOM id:
var tree = document.getElementById("tree");
tree DOM, :
tree.style.color = "red";
css javascript.
, /. , .tree, CSS. - jQuery ( ):
.tree
$('.tree').each(function() { this.style.color = "red"; });
CSS:
$('.tree').css('color', 'red');
( , , JS. $(...) - jQuery .tree. jQuery, .)
$(...)
tree , ( ), getElementById . .
for( var i in document.getElementsByTagName("tree") ){ document.getElementsByTagName("tree")[i].style.color = "red"; }
, , , . - , CSS, .
, : jQuery.Rule
, , , . , , , , jQ, .
: , . , <style> . , JS.
<style>
Firebug CSS .
CSS- , - . .
, AJAX CSS .
" , , ".
, , ( "ajax" ) , , , ?
/ Firefox ?
, .
. / .
: cookie javascript.
: , - .
, , element.style.color =. , .
element.style.color =