Asked  6 Months ago    Answers:  5   Viewed   15 times

Is it possible to make changes to a CSS rule-set dynamically (i.e. some JS which would change a CSS rule-set when the user clicks a widget)

This particular CSS rule-set is applied to lots of elements (via a class selector) on the page and I want to modify it when the user clicks the widget, so that all the elements having the class change.



You can, but it's rather cumbersome. The best reference on how to do it is the following article: Totally Pwn CSS with Javascript (web archive link).

I managed to get it to work with Firefox and IE - I couldn't in Chrome, though it appears that it supports the DOM methods.ricosrealm reports that it works in Chrome, too.

Tuesday, June 1, 2021
answered 6 Months ago

W3C CSS Transitions Draft

The completion of a CSS Transition generates a corresponding DOM Event. An event is fired for each property that undergoes a transition. This allows a content developer to perform actions that synchronize with the completion of a transition.


To determine when a transition completes, set a JavaScript event listener function for the DOM event that is sent at the end of a transition. The event is an instance of WebKitTransitionEvent, and its type is webkitTransitionEnd.

box.addEventListener( 'webkitTransitionEnd', 
    function( event ) { alert( "Finished transition!" ); }, false );


There is a single event that is fired when transitions complete. In Firefox, the event is transitionend, in Opera, oTransitionEnd, and in WebKit it is webkitTransitionEnd.


There is one type of transition event available. The oTransitionEnd event occurs at the completion of the transition.

Internet Explorer

The transitionend event occurs at the completion of the transition. If the transition is removed before completion, the event will not fire.

Stack Overflow: How do I normalize CSS3 Transition functions across browsers?

Tuesday, June 1, 2021
answered 6 Months ago

You could use the cssRules on the DOM stylesheet object corresponding to your original stylesheet to modify your rule.

var sheet = document.styleSheets[0];
var rules = sheet.cssRules || sheet.rules;

rules[0].style.color = 'red';

Note that IE uses rules instead of cssRules.

Here is a demonstration:

Friday, June 11, 2021
answered 6 Months ago

It is possible to detect supported CSS properties, provided you're aware in advance of what browser vendor prefixes you need to sniff for. I've written a gist for the mechanism:

cssSandpaper is a JS library that aims to parse CSS and dynamically implement polyfills for various CSS3 effects:

There is also a jQuery library that operates in reverse order, and silently implements transitions where possible when you call $.animate():

Friday, August 13, 2021
answered 4 Months ago

You can pass any transform property as a string.


It can be done like this; = "translate(x,y)"

I find out that if I write = "translate(someValue)"

It only affects x axes.

"translate-y(someValue)" or "translate-x(someValue)"

did not work out.

Or you can use rotate property; = "rotate(50px)".

Try it!

Saturday, September 18, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :