Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get CSS from element, put in JSON-Array, change element, restore element with stored CSS array

Tags:

json

jquery

css

So I want to get the css from a particular Element, put it in JSON-array, change element around, later restore the css of the element from the stored Array.

I tried:

var currentCSS = $(this).css;

The output is something like:

function (a,c) if(arguments.length....

So that seems it takes the function out of the jQuery, that's not what I want...

I could iterate through the wanted individual arguments, but there should be a better way...

Then later offcourse I'd try something like:

$(this).css(currentCSS);

But there might be no elegant solution to doing this...

like image 252
TrySpace Avatar asked Feb 28 '26 01:02

TrySpace


1 Answers

If all you are after is inline style as opposed to all of the style properties:

var $el=$(elem)
var style=$el.attr('style');
$el.removeAttr('style');


/* put style back*/

$el.attr('style',style);

Similarly after you have manipulated it, removing any inline adjustments that your code makes ... removing style attribute should put it back to whatever original css was applied

like image 89
charlietfl Avatar answered Mar 01 '26 15:03

charlietfl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!