O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing Drag and Drop

$("#drag1, #drag2, #drag3").draggable(   {helper:"clone", cursor:"move",    opacity:.7, zIndex:99}); $("#drop").droppable({accept:"img",   tolerance:"intersect", hoverClass:"drop-hover"}); $("#drop").on("drop", function(e,ui){   var item = $("<div></div>");   item.append($("<img></img>").attr("src",     ui.draggable.attr("src")));   item.append($("<span></span>").html(     ui.draggable.attr("src")));   $(this).append(item); });

You can define one element to be draggable and then another to be droppable. When draggable elements are dropped on droppable widgets, you can add JavaScript and jQuery code that provides whatever interaction necessary when draggable elements are dropped on ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required