Enhance the efficiency of your code by adding a class to the boxes. Below is the updated code for reference:
HTML
<div>
<div class="box" id="red"></div>
<div class="box" id="blue"></div>
<div class="box" id="green"></div>
<div class="box" id="yellow"></div>
<div class="box" id="gray"></div>
<div class="box" id="voilet"></div>
<div class="box" id="black"></div>
<div class="box" id="white"></div>
<div class="box" id="purple"></div>
<div class="clearfix"></div>
<p id="original">Show Original</p>
<p id="content-width">Low width</p>
</div>
Script
function openNav() {
document.getElementById("mySidenav").style.width = "270px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
$(document).ready(function () {
$(".index_top,.about-text,.navbar-dark .navbar-nav .nav-link:focus, .navbar-dark .navbar-nav .nav-link:hover, .navbar-dark .navbar-nav .active > .nav-link, .navbar-dark .navbar-nav .nav-link.active, .navbar-dark .navbar-nav .nav-link.show, .navbar-dark .navbar-nav .show > .nav-link,.navbar-dark .navbar-nav .nav-link:focus, .navbar-dark .navbar-nav .nav-link:hover, .navbar-dark .navbar-nav .active > .nav-link, .navbar-dark .navbar-nav .nav-link.active, .navbar-dark .navbar-nav .nav-link.show, .navbar-dark .navbar-nav .show > .nav-link").css("background-color", localStorage.getItem("default"));
$("#content-width").click(function () {
$("#content").css({
"width": "900px",
"margin": "auto",
"border": "1px solid #ddd",
"background-color": "white"
});
$("#myMap").css({
"width": "370px",
"height": "300px",
});
$(".navbar-expand-md .navbar-nav .nav-link").css({
"padding-right": "2.6rem",
"padding-left": "2.6rem"
});
$("body").css("background-color",localStorage.getItem("default"));
});
$("#original").click(function () {
$(".index_top,.about-text,.navbar-dark .navbar-nav .nav-link:focus, .navbar-dark .navbar-nav .nav-link:hover, .navbar-dark .navbar-nav .active > .nav-link, .navbar-dark .navbar-nav .nav-link.active, .navbar-dark .navbar-nav .nav-link.show, .navbar-dark .navbar-nav .show > .nav-link,.navbar-dark .navbar-nav .nav-link:focus, .navbar-dark .navbar-nav .nav-link:hover, .navbar-dark .navbar-nav .active > .nav-link, .navbar-dark .navbar-nav .nav-link.active, .navbar-dark .navbar-nav .nav-link.show, .navbar-dark .navbar-nav .show > .nav-link").css("background-color", "#2a3637");
$("#nav").css("border-bottom", "5px solid #2a3637");
$("#logo_img").attr("src", "images/logo.png");
$(".for-bold-text").css("color", "#2a3637");
$("#content").css({
"width": "auto",
"margin": "auto",
"border": "none",
"background-color": "white"
});
$("#myMap").css({
"width": "500px",
"height": "400px",
});
$(".navbar-expand-md .navbar-nav .nav-link").css({
"padding-right": "4.25rem",
"padding-left": "4.25rem"
});
$("body").css("background-color", localStorage.getItem("default"));
});
$(".box").click(function () {
var color = $(this).css("background-color");
var image = "images/logo_"+$(this).attr("id");
changeColor(image, color)
});
function changeColor(image, color){
$(".index_top,.about-text,.navbar-dark .navbar-nav .nav-link:focus, .navbar-dark .navbar-nav .nav-link:hover, .navbar-dark .navbar-nav .active > .nav-link, .navbar-dark .navbar-nav .nav-link.active, .navbar-dark .navbar-nav .nav-link.show, .navbar-dark .navbar-nav .show > .nav-link,.navbar-dark .navbar-nav .nav-link:focus, .navbar-dark .navbar-nav .nav-link:hover, .navbar-dark .navbar-nav .active > .nav-link, .navbar-dark .navbar-nav .nav-link.active, .navbar-dark .navbar-nav .nav-link.show, .navbar-dark .navbar-nav .show > .nav-link").css("background-color", color);
$("#nav").css("border-bottom-color", color);
$("#logo_img").attr("src", image);
$(".for-bold-text").css("color", color);
localStorage.setItem("default", color);
}
});