jQuery - Interaction Drop-able



Description

The Drop-able function can be used with interactions in JqueryUI.This function can be enabled drop-able functionality on any DOM element.We can drop the drag-able element by clicking on it with mouse.

Syntax

Here is the simple syntax to use drag-able −

$( "#droppable" ).droppable();

Example

Following is a simple example showing the usage of drop-able −

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://www.tutorialspoint.com/jquery/jquery-3.6.0.js">
      </script>
		
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js">
      </script>
		
      <script type = "text/javascript" language = "javascript">
   
         $(function() {
            $( "#draggable" ).draggable();
				
            $( "#droppable" ).droppable({
               drop: function( event, ui ) {
                  $( this ).addClass( "ui-state-highlight" ).find( "p" ).html( "Dropped!" );
               }
            });
         });
		 
      </script>
		
      <style>
         #draggable { width: 100px; height: 100px; 
            padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
         #droppable { width: 150px; height: 150px; 
            padding: 0.5em; float: left; margin: 10px; }
      </style>
   </head>
	
   <body>
      <div id = "draggable" class = "ui-widget-content">
         <p>Drag</p>
      </div>

 
      <div id = "droppable" class = "ui-widget-header">
         <p style = "background-color: aquamarine;height: 50;">Drop here</p>
      </div>
	 
   </body>
</html>

This will produce following result −

jquery-interactions.htm
Advertisements