0

Is there any way I can get all styles of an element as a variable and then add them to a style attribute?

I was thinking something along the lines of

var styles = $(this).css();
$('#element').attr('style', styles);

or

var styles = $(this).css();
$('#element').css({styles});

But it's not working. I feel like there may be more to it and it's not as simple as I'm hoping.

Any help would be great!

Nick
  • 2,261
  • 5
  • 33
  • 65
  • might work `$('#element').attr("style", window.getComputedStyle(this).cssText)` – Satpal Mar 23 '15 at 09:57
  • Hi @Jamiec I did see this but couldn't make sense of what it was telling me to do. – Nick Mar 23 '15 at 10:03
  • The accepted answer, and second-highest-voted answer show how to read all css styles from a given element and apply them to another element. Both answers have the code used in the actual answer. – Jamiec Mar 23 '15 at 11:01

0 Answers0