From a460a5297a3c3ec61db2471963053d3b75b1f814 Mon Sep 17 00:00:00 2001 From: skeddles Date: Fri, 22 Oct 2021 13:17:16 -0400 Subject: [PATCH] changed all color deselections to use optional chaining used optional chaining (?. ) intead of a variable / if statements, and added it to the missing _addColorButton function --- js/_addColorButton.js | 2 +- js/_clickedColor.js | 3 +-- js/_createColorPalette.js | 3 +-- js/_mouseEvents.js | 3 +-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/js/_addColorButton.js b/js/_addColorButton.js index 7cb5f3f..17871db 100644 --- a/js/_addColorButton.js +++ b/js/_addColorButton.js @@ -39,7 +39,7 @@ on('click', 'add-color-button', function(){ while (colorIsUnique == false); //remove current color selection - document.querySelector('#colors-menu li.selected').classList.remove('selected'); + document.querySelector('#colors-menu li.selected')?.classList.remove('selected'); //add new color and make it selected var addedColor = addColor(newColor); diff --git a/js/_clickedColor.js b/js/_clickedColor.js index 1f852c7..9f0a7d5 100644 --- a/js/_clickedColor.js +++ b/js/_clickedColor.js @@ -4,8 +4,7 @@ function clickedColor (e){ //left clicked color if (e.which == 1) { // remove current color selection - var selectedColor = document.querySelector('#colors-menu li.selected'); - if (selectedColor) selectedColor.classList.remove('selected'); + document.querySelector('#colors-menu li.selected')?.classList.remove('selected'); //set current color for (let i=1; i