Question

Is it possible to enable dragging when the mouse is clicked on the children of a div and have it drag the parent?

In this example I am trying to get the draggable to work for both the div and the select. When you click on the select and try to drag nothing happens.

http://jsfiddle.net/Trhs4/5/

<div id="draggable" class="ui-widget-content">
<select>
<option>Drag Me</option>
</select>
</div>

 $(function() {
     $( "#draggable" ).draggable();
 });
Was it helpful?

Solution

Here is an example : LIVE DEMO

It is not very compatible with your combobox because it catch the mouse click event to display its options, but it is working.

$(document).ready(function(){
      var click = false,
      top = null,
      left = null;

    $(document).bind('mousemove', function (e) {
        if (click == true) {
           $('#draggable').css({
             left: e.pageX - left,
             top: e.pageY - top
           });
        }
    });

    $('#draggable').draggable().click(function(e) {
        top = e.pageY - $('#draggable').position().top; 
        left = e.pageX - $('#draggable').position().left;
        click = !click;
        return false;
    });

    $('html').click(function() {
        click = false;
    });
});

OTHER TIPS

I dont think its possible due to how selects work with different browsers. You could build your own select with UL and LI.

Or you could add a [drag me] above the select that users could opt to hide. <-- that is more user-friendly anyways.

I don't think it's possible because of event handler. <option> has its own event handler so it prevents a drag&drop event from JQuery to trigger. You may try other object like <ul> and <li>. Please take a look at this sample: jquery sample

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top