views:

271

answers:

4

Hi All, i have a problem that i cant understand what to pass in the draagable function to make an elemnt draagable. I want to make my draggable through its id test. Can anyone tell me how to do this.

Code Sample

normal_tag11=' <div style="position:fixed" id="Normal_Tag1_div_dummy'+count1+'" class ="Normal_Tag1_div_dummy" >'+ 'Normal DUMMY</div>'; 
var id='Normal_Tag1_div_dummy'+count1; document.getElementById('droppable').innerHTML+=normal_tag11; 
$('#id').draggable({ });
A: 

Check this demo. The code is really simple.

RaYell
+1  A: 
$("#test").draggable();

if you are using jQueryui

$("#test")

selects your div element with id 'test'

In your code you have no element with id 'id'. Change your code

normal_tag11=' <div style="position:fixed" id="Normal_Tag1_div_dummy'+count1+'" class ="Normal_Tag1_div_dummy" >'+ 'Normal DUMMY</div>'; 
var id='#Normal_Tag1_div_dummy'+count1; document.getElementById('droppable').innerHTML+=normal_tag11; 
$(id).draggable();
rahul
But #test is written in double quotes so it will turn into a string.how will it take the id
That's how jQuery works. Don't worry about it being a string.
Makram Saleh
But it is not working
edited the answer
rahul
+1  A: 

You don't need to pass any parameters to draggable().

Check that you're actually including a build of jQuery UI that includes draggable (draggable isn't part of jQuery proper).

Otherwise, look for other bugs in your code that may be preventing the line where draggable is called from being executed.

Regarding the code sample you added, if your intent is to select the element with an id as defined in the id variable (as opposed to the element with an id of "id", as you are currently selecting), you should be using:

$(id).draggable();
bryan
A: 

normal_tag_d=' '+ 'Normal DUMMY'; document.getElementById('droppable').innerHTML+=normal_tag_d; var idx='#Normal_Tag1_div_dummy'+count1; $(idx).draggable({ revert: 'invalid'

        });

I have done phoenix what ou told me to do then too its not working. Please check if i have done any mistakes. Thanks.

i have also tried it like this:normal_tag_d=' <div style="position:fixed" id="Normal_Tag1_div_dummy'+count1+'" class ="Normal_Tag1_div_dummy" >'+ 'Normal DUMMY</div>';document.getElementById('droppable').innerHTML+=normal_tag_d;var idx='#Normal_Tag1_div_dummy'+count1; $(idx).draggable({ revert: 'invalid' });But this is not working
Please reply me .i m struck in this from a long time
Thanks phoenix for the answers now its working