Search code examples
jqueryjquery-uidraggablejquery-draggable

How to make div draggable by an image inside


I have a div and I am trying to drag it by a image inside the div. Below is my html

  <div id="MainDiv">
  <img src="Images/Drag.png"/>

<div>Test</div><div>Tes2</div>
</div>

I have made the main div draggable but I want to drag with the help of image drag.png which is inside the maindiv. How to achieve this .Please help me on this..


Solution

  • You can use the handle-option of the draggable-function:

    $( "#MainDiv" ).draggable({
        handle: "img"
    });
    

    Demo

    Reference

    draggable - handle