Skip to content
Related Articles

Related Articles Drag & Drop onDrop Option

View Discussion
Improve Article
Save Article
  • Last Updated : 20 Nov, 2020
View Discussion
Improve Article
Save Article

This Drag & Drop onDrop Option is used to call the callback function which is called when a suitable drag-gable element is dropped onto the drop target and the target accepts it.


    {onDrop: 'callbackFunction'}


  • function: This option takes the callback function.



<!DOCTYPE html>
    <script type="text/javascript" 
    <script type="text/javascript"
        src="scriptaculous.js?load = effects,controls">
    <script type="text/javascript">
        window.onload = function () {
                .each(function (item) {
                    new Draggable(item, { 
                        revert: true, 
                        ghosting: true 
            Droppables.add('droparea', { 
                hoverclass: 'hoverActive', 
                onDrop: moveItem 
            // Set drop area default non cleared.
            $('droparea').cleared = false;
        function moveItem(draggable, droparea) {
            if (!droparea.cleared) {
                droparea.innerHTML = '';
                droparea.cleared = true;
            alert("Image dropped successully")
    <style type="text/css">
        #draggables {
            width: 550px;
            height: 73px;
        #gfg {
            width: 550px;
            height: 73px;
        #droparea {
            float: left;
            width: 650px;
            height: 90px;
            border: 2px solid gray;
            text-align: center;
            font-size: 16px;
            padding: 12px;
        <h1 style="color: green">
        <p>A Computer Science Portal for Geeks</p>
    <strong> Drag & Drop 
        onDrop Option
    <div id="draggables">
        <img src=
    <div id="droparea">
        Drag the Image and Drop Your 
        Image in this area

Output: You can see the alert showing after successfully dropping the image.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!