_mercury – 01-38 Nov 24

I want to create a new input with new incremental class by jquery
$(document).ready(function () {
let serialCounter = 1;
const serialInput = `<input type="text" required class="w-80 block mt-4 s-${serialCounter}" >`;

$(".c-1").keyup(function (e) {
if (e.keyCode == 13) {
const c_1_value = $(".c-1").val();
// if there is a serial
if (c_1_value.trim() !== "") {
$(".serials-container").show();
$(".serials").append(serialInput);
}
// disable cartoon input
$(".c-1").prop("disabled", true);
}
});

//first serial input
$("body").on("keyup", ".s-" + serialCounter, function (e) {
if (e.keyCode == 13) {
const s_value = $(".s-" + serialCounter).val();
// if there is a serial
if (s_value.trim() !== "") {
serialCounter++;
console.log(serialCounter);
$(".serials").append(serialInput);
}
}
});
});
$(document).ready(function () {
let serialCounter = 1;
const serialInput = `<input type="text" required class="w-80 block mt-4 s-${serialCounter}" >`;

$(".c-1").keyup(function (e) {
if (e.keyCode == 13) {
const c_1_value = $(".c-1").val();
// if there is a serial
if (c_1_value.trim() !== "") {
$(".serials-container").show();
$(".serials").append(serialInput);
}
// disable cartoon input
$(".c-1").prop("disabled", true);
}
});

//first serial input
$("body").on("keyup", ".s-" + serialCounter, function (e) {
if (e.keyCode == 13) {
const s_value = $(".s-" + serialCounter).val();
// if there is a serial
if (s_value.trim() !== "") {
serialCounter++;
console.log(serialCounter);
$(".serials").append(serialInput);
}
}
});
});
but the class s-? does not increment ?
M
_mercury512d ago
$(".serials").append(serialInput); this line append the new el but still with s-1 not s-2 ?
UU
Unknown User511d ago