Abdul Saboor
Abdul Saboor

Reputation: 11

What is "CSS on-the-fly"?

What is CSS on-the-fly? Does JavaScript allow to modify CSS on-the-fly?

Upvotes: 1

Views: 566

Answers (3)

Saurabh Gokhale
Saurabh Gokhale

Reputation: 46415

Yes. It does allow you to modify the CSS on the fly.

Upvotes: 1

Michael Allen
Michael Allen

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

Tom Gullen
Tom Gullen

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

Related Questions