I have a table with numbers. When I click on a cell in the table, it toggles active state. I want to select one cell and press crtl and select another cell, and as result cells between first one and second will become active. How to implement it?
codepen https://codepen.io/geeny273/pen/GRJXBQP
<div id="grid">
<div class="cell">1</div>
<div class="cell">2</div>
<div class="cell">3</div>
<div class="cell">4</div>
<div class="cell">5</div>
<div class="cell">6</div>
</div>
const grid = document.getElementById("grid")
grid.onclick = (event) => {
event.stopPropagation();
const { className } = event.target;
if (className.includes('cell')) {
if (className.includes('active')) {
event.target.className = 'cell';
} else {
event.target.className = 'cell active';
}
}
}
It should work like shift highlighting and works in both directions