Solved

Drag and Drop

Posted on 2015-02-21
3
127 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 500 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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Building JSON/JQuery Results Display 11 52
Slush on text 2 25
Date Picker is picky (about something) 4 40
jQuery Tree with Draggable items 11 22
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

732 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