CodingDecoding
CodingDecoding

Reputation: 443

How to track the id of draggable div id in drop function

I have to find the id of draggable div in drop function using javascript. Using Jquery i know how to find it. but i am stuck in one condition where id of the dragged event is necessary in drop function. In drag function I am able to get id by using alert("id "+obj.id) but please help me out to find this in drop function using javascript.

Here is the code

function allowDrop(ev)
{
    ev.preventDefault();
}

function drag(ev, obj)
{
    ev.dataTransfer.setData("Text",ev.target.id);
    alert("id "+obj.id)
}

function drop(ev)
{
    farea1[i] = x[0].getElementsByTagName("termTxt")[i].getAttribute("correctCat");

    ev.preventDefault();
    var data=ev.dataTransfer.getData("Text");
    ev.target.appendChild(document.getElementById(data));


    i++;
    display();

    if(ev.target.id == "area1"){
        fans1[n]=farea1[k];
        k++;
        n++;
        countarea1++;   
    }
}

Upvotes: 0

Views: 149

Answers (2)

Milan Mendpara
Milan Mendpara

Reputation: 3131

You should be able to get that target div ID by :

  $(".droppable").droppable({
        drop: function(event, ui) {
            $('.display').html("Dropped in " + this.id);
        },
        over: function(event, ui) {
            $('.display').html( this.id );
        }
    });

Upvotes: 1

Murali N
Murali N

Reputation: 3498

Use this function to find the droppable id

$(function() {

        $( "#droppable" ).droppable({
            drop: function( event, ui ) {
                $( this ).html( "Dropped in " + this.id );
            }
        });
});

Upvotes: 1

Related Questions