What I am trying to do is to save the current tab background color in a var, and later use that var to change the body color. But why is it not working?
const tabName = 'someId';
var thisTabColor = document.getElementById(tabName).style.backgroundColor;
document.body.style.backgroundColor = thisTabColor;
#someId {
background-color: #cccccc; /* or whatever */
}
<body>
<div id="someId">Some text here</div>
</body>
In the above example, the body's background doesn't change to #cccccc
, the div
's color.