craig
craig

Reputation: 581

Checking if drag is on drop from button press

I understand the logistic of jQuery Ui and I have managed to create drag and drops well. However, I am having a problem in trying to check if a drag is on a drop from a button press. Here is some pseudo code of what I am trying to achieve

function checkAnswers(){ (called on button press)

If(Drag 2 is on Drop 1){
    (Drag 2).css('color', 'green')
}

If(Drag 3 or Drag 4  is on Drop 1){
    (Drag 3/4).css('color', 'red')
}

Apologies forgot to mention this is javascript

Upvotes: 0

Views: 97

Answers (1)

Robb
Robb

Reputation: 2686

You might be able to rig up something like this:

$("#draggable").draggable();
$("#droppable").droppable({
    drop: function () {
        alert("dropped");
    },
    over: function () {
        $( "#droppable" ).droppable( "option", "hoverClass", "drop-hover" );
    },
    out: function () {
        $( "#droppable" ).droppable( "option", "hoverClass", "" );
    },
    hoverClass: "drop-hover"
});
$("#btn").click(  function () {
    var hoverClass = $("#droppable").droppable( "option", "hoverClass" );    
    console.log(hoverClass);
    if(hoverClass === 'drop-hover') {
        console.log("hovered");
    } else {
        console.log("not hovered");
    }
});

fiddle

Upvotes: 2

Related Questions