Saturday, December 13, 2025
HomeLanguagesJavascriptscript.aculo.us Drag & Drop onDrop Option

script.aculo.us Drag & Drop onDrop Option

This script.aculo.us 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.

Syntax:

Droppables.add('element', 
    {onDrop: 'callbackFunction'}
);

Values:

  • function: This option takes the callback function.

Example: 

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
        src="prototype.js">
    </script>
      
    <script type="text/javascript"
        src="scriptaculous.js?load = effects,controls">
    </script>
      
    <script type="text/javascript">
        window.onload = function () {
            $A($('draggables').getElementsByTagName('img'))
                .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;
            }
  
            draggable.parentNode.removeChild(draggable);
            droparea.appendChild(draggable);
            alert("Image dropped successully")
        }
    </script>
  
    <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;
        }
    </style>
</head>
  
<body>
    <div>
        <h1 style="color: green">
            neveropen
        </h1>
  
        <p>A Computer Science Portal for Geeks</p>
    </div>
  
    <strong>
        script.aculo.us Drag & Drop 
        onDrop Option
    </strong>
      
    <div id="draggables">
        <img src=
    </div>
      
    <br>
    <div id="droparea">
        Drag the Image and Drop Your 
        Image in this area
    </div>
</body>
  
</html>


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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7200 POSTS0 COMMENTS
Thapelo Manthata
6897 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS