Get id of draggable div when dragging if I have many draggable div.using jquery

I have a lot of draggable divs. is there any way to get the id of the draggable div when dragging.

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

                     }
                         });

I am using jQuery Draggable

+3
source share
1 answer

thisalways refers to a DOM elementcall.

This way you can access this.idto get the current identifier.

Update

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

thisis a link to your DOM element(a div)

$(this) object, jQuery constructor $ function. , $(this)[0].id. obv.

+3

Source: https://habr.com/ru/post/1757605/


All Articles