I want to count some dynamic inputs that I generate with this code:
function AgregarPagoFechaVencimiento() {
var fecha = $("#FechaVencimientoPago").val();
var fechaFormato = formato(fecha);
var div = $("<div class='col-sm-3' id='pago"+ fechaFormato +"'>");
var divClose = $("</div>");
var divPago = $("<div class ='form-group'>");
var label = $("<label class='control-label'>Pago " + fecha + "</label>");
var inputPago = $("<input class= 'form-control pago'>").attr("type", "text");
div.append(divPago).append(label).append(inputPago).append(divClose).append(divClose);
return div;
}
And I'm trying to count how many are generated with this:
var count = $(".form-control pago").length;
console.log(count);
try this other:
var count = $(".payment").length; console.log(count);
and that:
var count= document.GetElementsByClass(".pago").length;
Any suggestion that I can implement so that it returns the count of how many generated elements there are?
Edit: HTML where the dynamic element is embedded:
<div class="row m-t-10" id="fechaPagoContainer"></div>
and this is the function that commands to call AddPayDateExpiration();
function AgregarTextBoxFechaVencimiento() {
var div = GenerarElementosDinamicosFechaVencimiento("");
var pagoFecha = AgregarPagoFechaVencimiento("");
$("#divCompraFechaVencimientoContainer").append(div);
$("#fechaPagoContainer").append(pagoFecha);
$("#FechaVencimientoPago").val("");
$("#btnAgregarFechaVencimientoPago").attr("disabled", "true");
var count = $(".form-control pago").length;
console.log(count);
}