The drag event is not firing.
const items = document.querySelectorAll(".item");
items.forEach((item) => {
item.addEventListener("drag", (e) => {
e.preventDefault();
console.log(item);
item.classList.add("dragging");
});
});
.list {
display: flex;
column-gap: 1rem;
}
.item {
width: 50px;
height: 50px;
background-color: red;
}
.item.dragging {
background-color: blue;
}
<div class="list">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
I wanted it to set a class on being dragged but it didn;t even fire. I also added a preventDefault()
method but that didn’t work either.