3

i have many dragged div. is there is any way to get the id of the dragged div while dragging.

$(".table_div").draggable({
    drag: function() {
        var offset = $(this).offset();
        $(this).html(offset.left + ', ' + offset.top);

                     }
                         });

i am using jQuery Draggable

1 Answers1

3

this is always referenced to the DOM element of invocation.

So you can access this.id to get the current ID.

update

You have a read Why do I have to use $(this)?

this is a reference to your DOM element (a div)

$(this) is an object, created by the jQuery constructor $ function. You could also access the id by calling $(this)[0].id. But that would be unnecesary work obv.

Community
  • 1
  • 1
jAndy
  • 231,737
  • 57
  • 305
  • 359
  • thanks jAndy i tryed with $(this).id it is resulted as undefined can you differ $(this).id and this.id please because i am a beginner –  Aug 02 '10 at 06:42