I'm trying to write JavaScript code that will apply a FA tick icon to a day when clicked if there isn't already a tick there, and remove the tick if there is one. I have written code that appends the icon but cannot figure out how to remove it
here's what I have
HTML and JS:
const days = document.getElementsByClassName('day')
for (let i = 0; i < days.length; i++) {
days[i].addEventListener('click', function(e){
const tick = document.createElement('i');
tick.classList = 'fas fa-check-square fa-4x'
this.append(tick);
});
}
<div class="day">1</div>
<div class="day">2</div>
<div class="day">3</div>
<div class="day">4</div>
<div class="day">5</div>
<div class="day">6</div>
<div class="day">7</div>
<div class="day">8</div>
<div class="day">9</div>
<div class="day">10</div>