Skip to content
Permalink
5fb14b0e0a
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
41 lines (31 sloc) 884 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" name="bg" id="bg">
</form>
<script>
let picker = document.getElementById('bg');
let body = document.querySelector('body');
let keyName = "bgColor";
let bgColor = window.localStorage.getItem(keyName) || '#ffffff';
picker.addEventListener('change', function(event) {
let hex = this.value;
console.log(hex);
setBg(hex);
window.localStorage.setItem(keyName, hex);
})
function setBg(color){
body.style.backgroundColor = color;
picker.value = color;
}
setBg(bgColor);
</script>
</body>
</html>