With this code on browser many field are available by the user, it can change R,G,B, HEX VALUE, HUE ecc. I need to read only the Red value.
JavaScript
x
6
1
<input id="color_pick"type="color" value="#ff0000">
2
3
var toread = document.getElementById('color_pick');
4
toread.value # get the hex
5
toread.value.red() # would it be possible to get r?
6
I’ve read this document but cannot figure how to get the single R value from the input.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/color
Advertisement
Answer
Since you already have hexadecimal from node.value
property, you just have to convert it to integer.
JavaScript
1
6
1
function pickRedInt(){
2
var toread = document.getElementById('color_pick');
3
console.log("Red Value - "+parseInt("0x"+toread.value.slice(1,3)));
4
}
5
6
pickRedInt();
JavaScript
1
3
1
Try changing this:
2
<hr>
3
<input id="color_pick"type="color" value="#ff0000" onchange="pickRedInt()">