0

I am trying to get the id of the dragged element. I saw a few examples for JQuery, but could not find a solutions for the Vanilla equivalent. I tried it with this, however that seems to give me the document.

event will give me the dropped containers id instead.

let dropElements = document.getElementsByClassName('drop');

for (let item of dropElements) {
   item.addEventListener('dragover', (event) => {
       event.preventDefault();
   });
   item.addEventListener('drop', (event) => {
       event.target.innerHTML = 'Woooop';
   });
}

I am thinking that maybe it is not intended to be able to have access to the dragged item, and i must get it via the i.e. dragstart eventlistener?

Frizzant
  • 684
  • 1
  • 7
  • 28
  • https://stackoverflow.com/questions/34361379/are-arrow-functions-and-functions-equivalent-exchangeable – Quentin Nov 05 '19 at 09:54
  • @Quentin `this` works now. However I stil can't get the dropped image. Basicly i rewrote the function to be a normal function, not an arrow function, which enabled `this` to work. But now `event.id == this.id`, which does not really help me, since I wanted the dropped 's id. – Frizzant Nov 05 '19 at 10:14

0 Answers0