user407283
user407283

Reputation:

to get id of the dragged div while dragging if i hav many draggable div.using jquery

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

Upvotes: 3

Views: 134

Answers (1)

jAndy
jAndy

Reputation: 236162

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.

Upvotes: 3

Related Questions