tags:

views:

28

answers:

2

i am currently use Draggable in Jquery i am trying to make it so when you click on a div it will disable you from draging it i have the follow code be it seems to not work can anyone lead me in the right direction please

selected_div = $("input#selected_div").val();

 $("#68").draggable({ 
          containment: 'parent',
if(selected_div == 68){
          disabled: true,
}else{
          disabled: false,
}
          handle: 'drag_border',
          drag: function(e, ui) {
                 var top = ui.position.top;
                 var left = ui.position.left;
                 $("input#tuPBd0hm_top").val(top);
                 $("input#tuPBd0hm_left").val(left);
                 $("#top").html(top);
                 $("#left").html(left);
}
});

Thank you,

+1  A: 

An ID in html must begin with a letter, so "#68" really shouldn't select anything. Try putting a letterr a-z in the front of the ID.

jarrett
+1  A: 

try this:

var selected_div = $("input#selected_div").val();
var isDraggable;
if(selected_div == "68") isDraggable = true;
else isDraggable = false

$("#a68").draggable({ 
          containment: 'parent',
          disabled: isDraggable,
          handle: 'drag_border',
          drag: function(e, ui) {
                 var top = ui.position.top;
                 var left = ui.position.left;
                 $("input#tuPBd0hm_top").val(top);
                 $("input#tuPBd0hm_left").val(left);
                 $("#top").html(top);
                 $("#left").html(left);
          }
});

And if you want to be able to disable or enable the div from being draggable after the page has been loaded then look at jquery Draggable API and click the Methods tab

$("#a68").draggable("disable");
$("#a68").draggable("enable");

I hope this helps!

Mouhannad