Get Dropzone Instance/Object using jQuery
Easy way to access the Instance with jQuery, if it has already been initialized:
var dropzone = $(this).get(0).dropzone;
As described in issue #180
You can also use the built in Dropzone.forElement
function.
var myDropzone = Dropzone.forElement("#mydropzone");
As stated before, you can use dropzone's forElement
, which in turn just checks for element.dropzone
, where 'element' is the native one (not jquery obj). So, to merge, summarize, explain and expand the previous answers, you can do like this:
var element = $("#mydropzone")[0]; // this is the way jquery gives you the original dom
or better, in just plain js:
var element = document.querySelector("#mydropzone");
then get the dropzone like this:
element.dropzone
Or, more concise (plain js here):
var dzone = document.querySelector("#mydropzone").dropzone
Just for reference, the current dropzone's forElement
source:
Dropzone.forElement = function (element) {
if (typeof element === "string") {
element = document.querySelector(element);
}
if ((element != null ? element.dropzone : undefined) == null) {
throw new Error("No Dropzone found for given element. This is probably because you're trying to access it before Dropzone had the time to initialize. Use the `init` option to setup any additional observers on your Dropzone.");
}
return element.dropzone;
};
The script seems to add a dropzone
object to the given element
.
So you can do something like this :
var $dropZone = $("#mydropzone").dropzone({ /*options*/ });
// ...
$dropZone[0].dropzone.processQueue();