• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

Drag and Drop

Anybody know why the drop event is not working?  I followed the example in the html 5 book.

http://jsfiddle.net/isogunro/n8wauqdn/1/
0
Isaac
Asked:
Isaac
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
Well, you don't have any jquery code.  Here is a fiddle I found with the same html code  http://jsfiddle.net/ehoury/55uLpct4/

var $draggedItem;

$(document).ready(function () {
    // Drag
    $('.item').on('dragstart', dragging);
    $('.item').on('dragend', draggingEnded);
    
    // Drop
    $('.hole').on('dragenter', preventDefault);
    $('.hole').on('dragover', preventDefault);
    $('.hole').on('drop', dropItem);
});

/* DRAG functions */
function dragging(e) {
    $(e.target).addClass('dragging');
    $draggedItem = $(e.target);
}

function draggingEnded(e) {
    $(e.target).removeClass('dragging');
}

/* DROP functions */
function preventDefault(e) {
    e.preventDefault();
}
function dropItem(e) {
    var hole = $(e.target);
    if (hole.hasClass('hole') && hole.children().length == 0) {
        $draggedItem.detach();
        $draggedItem.appendTo($(e.target));
    }
}

Open in new window

0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
I do have jquery code. After comparing to the fiddle you found, I spelled a few things wrong like .preventDefault'.

Thanks though!
0
 
Scott Fell, EE MVEDeveloperCommented:
Glad you found the issue.  There was no jquery code in the link you provided.  Just html and css.  Sometimes it just takes a break...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now