Skip to content
Permalink
16e861d225
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
38 lines (27 sloc) 821 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.querySelector('#bg');
let body = document.querySelector('body');
picker.addEventListener('change', function(event) {
let hex = this.value;
body.style.backgroundColor = hex;
localStorage.setItem("myBgColor", hex);
});
// Get the current color
let bgColor = localStorage.getItem("myBgColor") || '#cccccc';
body.style.backgroundColor = bgColor;
picker.value = bgColor;
</script>
</body>
</html>