HRÓÐÓLFR
HRÓÐÓLFR

Reputation: 5992

jQuery Id of item being dragged

This seems like it should be a simple task, but I'm a noob as far as goes jQuery, so here's what I'm looking for:

I have something like this:

<div class=draggable id=thing1> some contents </div>
<div class=draggable id=thing2> some other contents </div>
.
.
.
<div class=draggable id=thingN> content </div>

with this Javascript:

$(function() {
  $(".draggable").draggable();
  // from inside this block, how can I know the id of the thing I'm dragging?
}

Upvotes: 2

Views: 145

Answers (1)

alex
alex

Reputation: 490567

Use the stop callback, and access the id property of this (a reference to the element being dropped).

$(".draggable").draggable({
   stop: function() { alert(this.id);  }
});

jsFiddle.

Upvotes: 2

Related Questions