R
Reactiflux

help-js

_mercury – 01-38 Nov 24

M_mercury11/24/2022
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 ? $(".serials").append(serialInput); this line append the new el but still with s-1 not s-2 ?
UUUnknown User11/24/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!