Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jQuery UI - Droppable Hover Highlight</title> <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script> <style> body{font-family:Arial, sans-serif; padding:20px;} #wrap{display:flex;gap:24px;align-items:flex-start;} #source{width:110px;height:70px;background:#04AA6D;color:#fff;border-radius:6px;display:flex;align-items:center;justify-content:center;cursor:move;text-align:center;} #target{width:180px;height:120px;border:2px dashed #999;border-radius:6px;background:#fafafa;display:flex;align-items:center;justify-content:center;text-align:center;color:#666;transition:background .15s, border-color .15s;} #target.ui-state-highlight{background:#eaf6ff;border-color:#2196f3;color:#2196f3;} </style> </head> <body> <h3>over / out - highlight while hovering</h3> <div id="wrap"> <div id="source">Drag me</div> <div id="target">Drop here</div> </div> <script> $(document).ready(function(){ $("#source").draggable({ revert: "invalid", helper: "clone" }); $("#target").droppable({ over: function(){ $(this).addClass("ui-state-highlight"); }, out: function(){ $(this).removeClass("ui-state-highlight"); }, drop: function(event, ui){ $(this).removeClass("ui-state-highlight").text("Dropped!"); } }); }); </script> </body> </html>
Output