How to directly change the css class?

Is it possible to use javascript to directly edit the contents of a .css file? (In turn, affects the style of elements that use the modifiable class?)

I saw several answers to such a question, but they all relate to the dynamic creation of HTML and CSS code in the html document itself, which I don't really want ...

Say, for example, I have the following code:

*{
    color:red;
}

This makes ALL the text in the document red. If I give the client the opportunity to reset and change the color of all the text to whatever he wants, then the most logical choice for me is to enter the .css file and edit the "color" value in the universal selector ...

Ideas?

+3
source share
8 answers

css , head- , , , "" , , .

( ) document.styleSheets, , .

, , , , .

+4

, , - - Javascript. , CSS .

+2

CSS JavaScript, .

, , PHP. PHP CSS.

<link rel="stylesheet" type="text/css" href="/path/to/css.php" />
0

, javascript css. jQuery, : http://api.jquery.com/css/.

0

...

var elements = document.getElementsByTagName('body')[0].getElementsByTagName('*');

for (var i = 0, length = elements.length; i < length; i++) {
    elements[i].style.color = '#f00';
}
0

, .css , . JavaScript .css , . , : , . , .

, - JavaScript, AJAX , , .css. , , , , , .

0

CSS, JavaScript


var filename = "matrix.css";
var css      = document.createElement("link");

css.setAttribute("rel", "stylesheet");
css.setAttribute("type", "text/css");
css.setAttribute("href", filename);
document.getElementsByTagName("head")[0].appendChild(css);
0

All Articles