Reputation: 11
What is CSS on-the-fly? Does JavaScript allow to modify CSS on-the-fly?
Upvotes: 1
Views: 566
Reputation: 5838
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
Upvotes: 1
Reputation: 61765
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.
Upvotes: 2