2

In this plunk I have a div that contains an input field readonly. I made the div draggable with jQuery UI.

When I drag the portion that is not hidden by the input field, it works fine (try dragging the orange area). But when I try to drag the div by dragging the input field, the div doesn't move. I need to drag the div even though the mouse is on any element included in the div. Is this possible?

Javascript:

$(function() {
    var div1 = $('#div1');
    div1.draggable();
    var input1 = $('<input type="text" readonly value="Some Text" style="position:absolute;top:0;left:0;border:0">');
    input1.appendTo(div1);   
})
ps0604
  • 1,227
  • 23
  • 133
  • 330

1 Answers1

1

I think this is what you need

$(function() {
    var div1 = $('#div1');
    var input1 = $('<input type="text" readonly value="Some Text" style="position:absolute;top:0;left:0;border:0">');
    input1.appendTo(div1);   
    $('#div1').draggable({
                cancel: ''
    });
});

Basically what cancel option does is it will cancel dragging options on those elements mentioned inside it. Since you do not want to cancel drag option on any child elements, just leave it blank.

You can find more information in this and this link and Here is the Working Plunk for your reference

Community
  • 1
  • 1
Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200