sandeep.mishra
sandeep.mishra

Reputation: 825

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..

Upvotes: 1

Views: 6928

Answers (2)

Siva Kannan
Siva Kannan

Reputation: 2461

JSFiddle

with jquery events $('#movable').on('mousedown',) possible without jquery UI also

Upvotes: 0

empiric
empiric

Reputation: 7878

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

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

Demo

Reference

draggable - handle

Upvotes: 5

Related Questions