开发者

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?
}
开发者_开发百科


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜