What is CSS on-the-fly? Does JavaScript allow to modify CSS on-the-fly?
Asked
Active
Viewed 447 times
1
-
Where did you see the term "CSS on-the-fly"? This is not a standard term that I've seen used. – Phrogz Feb 25 '11 at 17:44
3 Answers
2
Changing an Elements CSS Attributes
The easiest way to modify CSS on the fly is probably with Jquery:
$('#elementID').css("height", "300px");
First parameter is the CSS attribute, second is the new value.
Try and steer away from over using this, as it wont degrade nicely probably for people without Javascript enabled.
Changing CSS Classes
Related info: How can I change the css class rules using jQuery?
This afaik is not possible on the fly, see above link.

Community
- 1
- 1

Tom Gullen
- 61,249
- 84
- 283
- 456
1
Yes. It does allow you to modify the CSS on the fly.

Phrogz
- 296,393
- 112
- 651
- 745

Saurabh Gokhale
- 53,625
- 36
- 139
- 164
-
Yes, [it does](http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/stylesheets.html). – Phrogz Feb 25 '11 at 17:17
-
Oops. I misinterpreted the question. Editing. Btw, thanks for the link. – Saurabh Gokhale Feb 25 '11 at 17:17
-
I agree I gave wrong answer previously. But now I know it allows. Why still downvote ? – Saurabh Gokhale Feb 25 '11 at 17:21
1
You can also use .style to access css styles in javascript eg
document.getElementById("anElement").style.width = "300px";
Though I think this might only affect single elements

Michael Allen
- 5,712
- 3
- 38
- 63
-
Yes, modifying the style attribute on a particular element only affects the style of that element; it does not somehow go backwards and find classes or other selectors that apply to the element and modify the values in one or more of them. – Phrogz Feb 25 '11 at 17:50