My code is dynamically inserting an img tag into a div on a page.
I am using the Cropper plugin to try to crop this image. The plugin itself doesn't matter that much - I could equally use JCrop for example.
To use Cropper on an image that is already in the DOM it says do this:
HTML:
<div id="files">
<img src="path/to/img" />
</div>
JS:
$("#files > img").cropper({
autoCropArea: 0.6, // Center 60%
});
That's fine when the image already exists in the #files
div. But I am adding the image dynamically using ajax() calls to my server. I understand I need to delegate but I don't understand how to delegate an entire plugin?
I assumed something like this:
$(document).on("change", "#files > img", function(){
$(this).cropper({
autoCropArea: 0.6, // Center 60%
});
});
But it doesn't seem to be working. Any ideas?