开发者

jQuery Id of item being dragged

开发者 https://www.devze.com 2023-03-27 08:07 出处:网络
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:

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

精彩评论

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