Given a string of a valid CSS color value:
- #fff
- #ffffff
- white
- rgb(255, 255, 255)
Need to get an array of numbers of the following format: [R, G, B]
What is the most efficient way of doing this in JavaScript (assuming a major browser)?
Given a string of a valid CSS color value:
Need to get an array of numbers of the following format: [R, G, B]
What is the most efficient way of doing this in JavaScript (assuming a major browser)?
If you are trying to get an element's background-color, for example, you can use this:
While kennebec has mostly completed Kolink's answer, there are some improvements to be made. Firstly, we can support hsla and rgba, and in doing so it is best to always return an alpha value. Another minor improvement is made by applying the trim method to the incoming argument string.