I check if there is an element with jQuery or not by its id, but it throws me an error. This check is made in a callback within the instance of an element. I need to do that check there, since it is the point at which it collects the data and must save it in a hidden input. but if that input already exists, I do not need it to be created.
This process is repeated because there is a rise of several images, but the data I only want to save once.
This is my code:
var capturaCam = new Camera(
document.getElementById("camera-capt"),
function (dataUrl) {
var blob = dataURLToBlob(dataUrl);
var fileInfo = getFileInfoFromBlob(blob);
camsFiles.push(blob);
processImage(fileInfo);
var img_width = Camera.imagen.imgWidth;
if ( $("#img_width").length == 0 ) { //Si no existe
//crea el input hidden
jQuery("#form-hidden").append("<input type='hidden' id='img_width' name='jform[img_width]' value='"+ img_width +"' data-hj-masked />");
}
}
);
The error that shows is:
Uncaught TypeError: Cannot read property 'length' of null
at Camera.verifiedPhoto (cameraconst.js:427)
at Camera.onAccept (cameraconst.js:436)
at HTMLButtonElement.<anonymous> (Camera.js:676)
at HTMLButtonElement.dispatch (jquery.min.js:4)
at HTMLButtonElement.r.handle (jquery.min.js:4)
I imagine it has to do with some conflict with other methods to do this within the instance. Is there any other way to check if the input hidden exists or correct this error?