What is the preferred way to switch several css properties using jQuery and then switch them all back.
For example, if I set:
$element.css({ "background" : "white", "height": "50px", "width" : "30px" });
$anotherElement.css({ "overflow" : "hidden", "font-size": "12px", "padding" : "5px" });
$yetAnotherElement.css({ "top" : "10px", "font-weight": "bold" });
I used this specific count of elements with 2-3 different selectors for each to illustrate that it's not convenient to save each one by one and it's also not convenient to create "temporary classes" for each one especially if I had yetAnotherAnotherElement
and so on... And let's also say they're in different containers.
It would be nice to be able to get the css "object":
var oldCSS= $element.css();
$element.css({ ...change css... });
//Change back
$element.css(oldCSS);
Should also work nicely with arrays:
//Set
elements.each(function (index, element) {
array[index] = $(element).css();
});
//Restore
elements.each(function (index, element) {
$(element).css(array[index]);
});
Is there something like this?
UPDATE: turns out I can set $element.css(cssObject) already by default its just a matter of overriding a blank css() to return an object or string based on a flag. For example:
element.css("overflow", true)
would return { "overflow" : "hidden" }
element.css("position", "overflow", true)
would return { "position" : "absolute", "overflow":"hidden" }
Then it can be easily restored like I want: element.css(cssObject)