Skip to content
Advertisement

Get parent data element from dragged element – Drag en drop function

I am trying to retrieve a parent data attribute data-date of the dragged object in JavaScript. So i want to receive the data-date attribute <td> from where the div “drag me” was dragged from.

HTML example:

JavaScript

I am able to retrieve the dropped data-date attribute, but cant figure out how to retrieve the dragged from data-date attribute.

JS From and TO current code

JavaScript

Advertisement

Answer

I have found a work around to pass information from the draggable function to droppable function

In the example below i first get the data-date value from the parent element in the draggable function. After retrieving this data we pass the value from draggable to the droppable function.

We name de variable oldDate so we can access it in the droppable function by calling “ui.draggable.data(‘oldDate’)”. Ill provide an example code for you guys below.

Draggable function:

JavaScript

Droppable function:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement