Skip to content

Instantly share code, notes, and snippets.

@RshStone
Last active August 4, 2020 10:55
Show Gist options
  • Save RshStone/c902e17f207e397556a3d9b32b7d83a3 to your computer and use it in GitHub Desktop.
Save RshStone/c902e17f207e397556a3d9b32b7d83a3 to your computer and use it in GitHub Desktop.
use button to chooce the color you want
<canvas id = "d1">
</canvas>
<p><input type = "button" value = "change" onclick = "changeColor()">
</p>
<p>
<input type = "color" value = "001A57" id = "cls" onchange = "doColor()">
</p>
function changeColor(){
var dd1 = document.getElementById("d1");
dd1.style.backgroundColor = "green";
}
function doColor(){
var dd1 = document.getElementById("d1");
dd1.style.backgroundColor = "green";
var colorinput = document.getElementById("cls");
var color = colorinput.value;
dd1.style.backgroundColor =color;
}
canvas{
width:200pt;
height:100pt;
margin:10px;
border: 1px solid lightgray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment