Reactiflux
Reactiflux

help-js

Root Question Message

_mercury
_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);
            }
        }
    });
});

but the class s-? does not increment ?
_mercury
_mercury11/24/2022
$(".serials").append(serialInput);
this line append the new el but still with s-1 not s-2 ?
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy