I have an element with the Id box
, which has a background color set to rgba(0, 0, 0, 0.3)
on a white background. Like so:
#box {
width: 100px;
height: 100px;
margin: 10px;
background-color: rgba(0, 0, 0, 0.3);
}
<div id="box"></div>
Using a color picker, I can see that the box's color is in hex is #b2b2b2
. Now, what I want to know is there any way to get this hex code using JavaScript
without convert RGBA
to hex
format? I read about getComputedStyle
function, but could not get it to work. Any help is greatly appreciated.