Reputation: 333
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.
<div id="draggable" class="ui-widget-content">
<select>
<option>Drag Me</option>
</select>
</div>
$(function() {
$( "#draggable" ).draggable();
});
Upvotes: 2
Views: 976
Reputation: 14025
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;
});
});
Upvotes: 1
Reputation: 447
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
Upvotes: 0
Reputation: 1170
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.
Upvotes: 0