0

I want a javascript function which will take a color name as parameter and it returns the color rgb code.

Suman Biswas
  • 853
  • 10
  • 19
  • 2
    possible duplicate of [Javascript function to convert color names to hex codes](http://stackoverflow.com/questions/1573053/javascript-function-to-convert-color-names-to-hex-codes) – Thilo Jun 20 '14 at 09:54
  • Although the OP is asking for RGB not hex. You could use the same principle in that linked answer and create a map for the rgb values. rgb(255,255,255) being white, etc. Unless the OP actually means hex, in which case, carry on. :) – i-CONICA Jun 20 '14 at 09:58

1 Answers1

1

You could set the style to a html element, let's say the <div id='d1'></div>

then you could check the computed color:

    var d1 = document.getElementById('d1')
    var color = window.getComputedStyle(d1, null)['color']
Lifecube
  • 1,198
  • 8
  • 11