Skip to content
Permalink
5edcea6126
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
32 lines (28 sloc) 996 Bytes
<!DOCTYPE html>
<html>
<head>
<title>Color Picker</title>
</head>
<body>
<h1>Color Picker</h1>
<p> Change background color and save value locally</p>
<input type="color" id="colorPicker">
<script>
const colorPicker = document.getElementById('colorPicker');
// Set initial color from localStorage if available
const savedColor = localStorage.getItem('selectedColor');
if (savedColor) {
document.body.style.backgroundColor = savedColor;
colorPicker.value = savedColor;
}
// Listen for input and change events on the color picker
colorPicker.addEventListener('input', setColor);
colorPicker.addEventListener('change', setColor);
function setColor() {
const selectedColor = colorPicker.value;
document.body.style.backgroundColor = selectedColor;
localStorage.setItem('selectedColor', selectedColor);
}
</script>
</body>
</html>