Skip to content
Permalink
82c2a73def
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
30 lines (26 sloc) 829 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>
var picker = document.getElementById('bg');
var body = document.querySelector('body');
const keyName = 'colorSetting';
body.style.backgroundColor = localStorage.getItem(keyName);
bg.value = localStorage.getItem(keyName);
picker.addEventListener('change', function(event) {
let hex = this.value;
body.style.backgroundColor = hex;
localStorage.setItem(keyName, hex);
});
</script>
</body>
</html>