Richard Knop
Richard Knop

Reputation: 83697

How to get an id of element to which I drag a "draggable" element

So I have divs like this on my page:

<div class="drag"></div>

And this jquery code:

<script type="text/javascript">
    //<!--
$(document).ready(function() {

 $('.drag').draggable();

});    //-->
</script>

The draggable effect works well.

But I would like to find out an id of a HTML tag where the draggable div gets dropped. If it has any.

So if I drag the div to a table with id="my-table", I want to get that value inside js and do something with it.

Upvotes: 0

Views: 345

Answers (2)

jet
jet

Reputation: 708

I just noticed this post because I recently posted a very similar question, so I will just leave the link here in case anyone wants tot take a look.

How to find out about the "snapped to" element for jQuery UI draggable elements on snap

Upvotes: 0

Kennethvr
Kennethvr

Reputation: 2680

if you have a draggable you also have a droppable...correct?

so you could do something like this:

$("#draggable").draggable();
$("#droppable").droppable({
  drop: function() {
    alert('dropped');
    var dropId = $(this).attr('id');
  }
});

Upvotes: 1

Related Questions