?
Solved

Drag and Drop

Posted on 2015-02-21
3
Medium Priority
?
132 Views
Last Modified: 2015-02-21
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
Comment
Question by:Isaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 40623540
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
 
LVL 5

Author Comment

by:Isaac
ID: 40623571
I do have jquery code. After comparing to the fiddle you found, I spelled a few things wrong like .preventDefault'.

Thanks though!
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 40623572
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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question