Hi,
I have html like this:
<div id="inputarea" style="color:black;font-size:15px;">
I want to store the style data into a cookie so I did this:
setCookie('savedstyle',inputarea.style);
So in my next session inputarea should load the data from that cookie and set it as the style for the inputarea like this:
if(getCookie('savedstyle')) {
inputarea.style = getCookie('savedstyle');
}
nothing happens because the value stored in the cookie looks something like this: [object CSS properties]. Why is that? How can I store the value properly?
Thank you.
>Solution :
The .style in JS just stores setters for CSS attributes. It’s not useful for reading information.
If you just want to store the inline style use:
setCookie('savedstyle', inputarea.getAttribute('style'))
and to retrieve
inputarea.setAttribute('style', getCookie('savedstyle'))