Skip to content

Commit

Permalink
feat: display color code
Browse files Browse the repository at this point in the history
Signed-off-by: supr1yo <[email protected]>
  • Loading branch information
supr1yo committed Jan 5, 2024
1 parent 2fa3147 commit e686ed2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions BackgroundColorChanger/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<body>
<h1>Background Color Changer</h1>
<p id="hexcode"></p>
<div id="colorbox"></div>

<script src="script.js"></script>
Expand Down
5 changes: 5 additions & 0 deletions BackgroundColorChanger/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ function bgchange(color) {
var colorarray = ["#e58e26", "#f9b4ab", "#B1FB17", "#78e08f", "#fd79a8"];
var colorbox = document.getElementById("colorbox");

let hexcode = document.getElementById('hexcode');

colorarray.forEach(function (color, index) {
let span = document.createElement("span");
span.style.backgroundColor = color;
span.addEventListener("click", function () {
bgchange(index);

// Display the color code
hexcode.innerHTML = colorarray[index].toUpperCase();
});
colorbox.appendChild(span);
});
8 changes: 7 additions & 1 deletion BackgroundColorChanger/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ body {

h1 {
color: #6203e0;
margin-bottom: 2rem;
margin-bottom: 1rem;
}

p {
font-family: monospace;
padding: 5px;
font-size: large;
}

#colorbox {
Expand Down

0 comments on commit e686ed2

Please sign in to comment.