Skip to content
Permalink
07be3ba3db
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
46 lines (32 sloc) 979 Bytes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Color Picker</title>
</head>
<body>
<form>
<input type="color" id="head" name="head">
</form>
<script>
let picker = document.getElementById('head');
let body = document.querySelector('body');
//can use keyname to set "color" as a variable
picker.addEventListener('change', function(event){
let hex = this.value;
body.style.backgroundColor = hex;
let newColor = this.value;
localStorage.setItem("color", hex);
});
window.addEventListener("load", function(event){
let hex = this.value;
localStorage.getItem("color", hex);
console.log(localStorage.getItem("color", hex));
body.style.backgroundColor = (localStorage.getItem("color", hex));
//picker.value = "color";
});
</script>
</body>
</html>