I have some DOM element which is draggable using jQuery UI.All are working fine but when i create some element using jQuery , then they are not draggable at all. i.e
$('div.draggable').draggable(); //Existing element , it works :)
$('p.draggable').draggable() ; //Newly created paragraph with same class name, it doesnt work at all :(
Thanks in advance !!!
I am trying This :
<script type="text/javascript">
$(document).ready(function(){
$('body').append('<p class="draggable">Newly Created Paragraph</p>');
$('p.draggable').draggable(); **//This is not working**
});
</script>
However Somehow this is working
<script type="text/javascript">
$(document).ready(function(){
$('body').append('<p class="draggable">Newly Created Paragraph</p>')
.find('p.draggable').draggable(); **This is working**
});
</script>
You need to call draggable() after the newly created element is inserted into the DOM.
The reason being, is that the first line of code is only matching existing elements. Newly created elements aren't selected in that first line.
Actually it seems that there is problem with draggable. When you append some htmlTag and then try to find it and make it draggable, it do not recognise it. try to make a new element using
createElement
and then append it. Hope it worksor
You can use setTimeout to call draggable function after the new element has made.
You should call draggable() function everytime you call an event action:
i had this problem but after reading this i could solve it. so you have to call again draggable() method after building your new element, this is my code:
You have to apply draggable on the instance of the newly created object, Rewritten code:
It should work now.