Permalink
Cannot retrieve contributors at this time
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?
2024-spring-dmd-3475/week-09/3. Background changer app/index.html
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
32 lines (28 sloc)
996 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |