_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 ?
2 Replies
_mercury πŸ‡΅πŸ‡Έ
$(".serials").append(serialInput); this line append the new el but still with s-1 not s-2 ?
reactibot
reactibotβ€’3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1045151489955479663