I am trying to load a background color of a clicked box to the array of rgb.
As you can see when I use rgb1 = color.split(",")
this creating array of string like
[
"49",
" 133",
" 155"
]
So I tried to parse the items to int like rgb2 = parseInt(color.split(","));
but now I am juts getting 49
on return.
How can I export the result like so?
[49 , 133, 155]
Code:
$(".box").on("click", function () {
color = $(this).css("background-color").substring(4).slice(0,-1);
rgb1 = color.split(",");
rgb2 = parseInt(color.split(","));
console.log(color);
console.log(rgb1);
console.log(rgb2);
});
.box{
height:30px;
width:30px;
background:#31859B;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box"></div>