0

How could the following code be changed so that the jQuery would know when a new DIV is added and it could apply for this newly created DIV, too?

The new DIV contains an image and is added after image is uploaded.

<script>
$(function() {
$( ".divTestImg" ).draggable();
});
</script>
Trinimon
  • 13,839
  • 9
  • 44
  • 60
Gugols
  • 63
  • 1
  • 9
  • Apply what to this newly created `div`? Where is the code for adding the new `div`? – Jay Na Apr 23 '13 at 17:13
  • **Listening** for these events is not a common approach. But if you insist, I think it has been asked: (stackoverflow.com/questions/9470931/…) But again, it is a more common approach that **you** tell jQuery what to do at the moment when **you** add a new div element. In your case, *after the image is uploaded*. Makes sense? – Terry Young Apr 23 '13 at 18:13

1 Answers1

0

When you add the new div, call .draggable on it.

newDiv.appendTo("body").draggable();
Kevin B
  • 94,570
  • 16
  • 163
  • 180