Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spectrum color picker get the value of the color

I implemented Spectrum's color picker just fine

$(document).ready(function() {
  $("#font_color").spectrum({
    color: "#f00"
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/bgrins/spectrum/master/spectrum.js"></script>
<link href="https://cdn.rawgit.com/bgrins/spectrum/master/spectrum.css" rel="stylesheet"/>

<input type="text" id="font_color" />

But I don't know how to get the value inside the texfield using javascript. Can someone help me?

like image 242
mengmeng Avatar asked Oct 11 '13 18:10

mengmeng


3 Answers

Another way to also get it, if the input field method does not work for you, is directly from spectrum itself.

$("#font_color").spectrum('get');

or

$("#font_color").spectrum('get').toHexString();

To get it converted.

like image 51
Bob Tate Avatar answered Nov 14 '22 09:11

Bob Tate


the value of the input?

var value = $("#font_color").val();
like image 20
Dvir Avatar answered Nov 14 '22 08:11

Dvir


Use color.toRgbString() work for me

like image 34
user2888692 Avatar answered Nov 14 '22 07:11

user2888692