JS изменить атрибут name при добавлении поля по клику

 $(document).on("click", ".cild_plus", function () {
    var child = $('#chilg').val();
    var adults = $('#adult_val').val();
    if (adults < 4) {
        adults = Number.parseInt(adults) + 1;

        if (child < 2) {
            child = Number.parseInt(child) + 1;
            $('#chilg').val(child);
            $('#adult_val').val(adults);
            var nevadultstext = adults + " " + declOfNum(adults, ['гость', 'гостя', 'гостей']);
            $('#span-guests').text(nevadultstext);
            var childtext = child + " " + declOfNum(child, ['ребенок', 'ребенка', 'детей']);
            $('#children_text').val(childtext);
            $('#kids_ages_block').show();
            $("#div_kids_ages").prepend('<div class="input-group kid-age-block"><div class="input-group-prepend">' +
              '<button type="button" onclick="$(this).parent().parent().find(\'input\').val(Math.max(+$(this).parent().parent().find(\'input\').val()-1,0))">;$(this).parent().parent().find(\'input\').attr(\'value\',$(this).parent().parent().find(\'input\').val());$(\'#menu\').html($(\'div[class=popover-content]\').html());" class="btn btn-light"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-minus"><line x1="5" y1="12" x2="19" y2="12"></line></svg></button></div> <input readonly="readonly" name="kid1" type="text" class="form-control text-center" value="2"> <div class="input-group-append"><button type="button" onclick="$(this).parent().parent().find(\'input\').val(Math.min(+$(this).parent().parent().find(\'input\').val()+1,17));$(this).parent().parent().find(\'input\').attr(\'value\',$(this).parent().parent().find(\'input\').val());$(\'#menu\').html($(\'div[class=popover-content]\').html());" class="btn btn-light"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-plus"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg></button></div></div>');
        }

    }
    

});

Есть такая вот функция, при нажатии на которую появляются поля с количеством детей. В поле вводится возраст ребенка. И все бы нормально, но нужно при добавлении ребенка добавлять вместо name="kid1" name="kid2". Кто-нибудь понимает как втиснуть это в сторку?


Ответы (0 шт):