Actually like this I create

$("#addLesson").click(function(){ var inputVal=$("#idLesson").val(); if(inputVal){ var divStart = "<div class='well col-md-6 col-sm-8 col-xs-12 draggable'>"+inputVal+"<span class='glyphicon glyphicon-remove del'></span></div>"; $(blockLesson).append(divStart); } }); 

here so I try to connect

 $('#blockLesson').on( 'click',"div",draggable()); 

the console gives such an error

ReferenceError: draggable is not defined

and so I try

 $('#blockLesson').on( 'draggable',"div"); 

and so

 $('#blockLesson').on( 'click',"div",function(){$(this).draggable()}); 

that does not work.

  • what's the draggable function? it is possible that you just need to omit () - Grundy
  • @Grundy here is the proper function jqueryui.com/draggable itself - Sergalas
  • It is worth going to this link and see how this function is used :-) I can immediately say that in the example in question there is a completely different draggable function that is not related to the link that is Grundy
  • @Grundy so I want to understand how to properly connect this function to the newly created elimen - Sergalas
  • @Grundy I completely changed the essence of the question so it seems to me more correct - Sergalas

1 answer 1

This function initializes the plugin. If it needs to be initialized on a new element, then it is necessary to get this element and initialize it.

This place is going to html

 var divStart = "<div class='well col-md-6 col-sm-8 col-xs-12 draggable'>"+inputVal+"<span class='glyphicon glyphicon-remove del'></span></div>"; 

Instead, you can immediately create a jQuery object

 var divStart = $("<div class='well col-md-6 col-sm-8 col-xs-12 draggable'>"+inputVal+"<span class='glyphicon glyphicon-remove del'></span></div>"); 

To which you can already apply the specified function

 divStart.draggable();