0

Есть jquery-скрипт, который делает проверку инпутов на правильность их заполнения. HTML:

<div class="players">
            <div class="player">
                <input type="text" class="input_firstname player_input" name="player[][firstname]" placeholder="Введите имя">
                <input type="text" class="input_lastname player_input" name="player[][lastname]" placeholder="Введите фамилию">
                <input type="text" class="input_birthday player_input" name="player[][birthday]" placeholder="Введите дату рождения">
                <input type="text" class="input_passport player_input" name="player[][passport]" placeholder="Серия и номер паспорта">
                <i class="fa fa-check" aria-hidden="true"></i>
            </div>
            <div class="player">
                <input type="text" name="player[][firstname]" placeholder="Введите имя">
                <input type="text" name="player[][lastname]" placeholder="Введите фамилию">
                <input type="text" class="input_birthday" name="player[][birthday]" placeholder="Введите дату рождения">
                <input type="text" class="input_passport" name="player[][passport]" placeholder="Серия и номер паспорта">
                <i class="fa fa-check" aria-hidden="true"></i>
            </div>  </div>

Сейчас добавил кнопку

<a href="#addplayers" class="a_success">Добавить игрока</a>

Которая добавляет еще 1 <div class="player"> jQuery:

    $("[href='#addplayers']").click(function(){
    $('.players').append("<div class='player'><input type='text' name='player[][firstname]' style='margin: 5px 2px 0 0 !important;' placeholder='Введите имя'><input type='text' name='player[][lastname]' style='margin: 5px 2px !important;' placeholder='Введите фамилию'><input type='text' class='input_birthday' name='player[][birthday]' style='margin: 5px 2px !important;' placeholder='Введите дату рождения'><input type='text' class='input_passport' name='player[][passport]' style='margin: 5px 2px !important;' placeholder='Серия и номер паспорта'><i class='fa fa-check' aria-hidden='true'></i></div>");
});

Вопрос - тот скрипт, что действует на див player, не работает с дивами, которые вставлены путем append(). Скажите, пожалуйста, как решить эту проблему?

1
  • А покажите скрипт, который проверку делает?
    – TO220
    7 июн 2017 в 2:49

1 ответ 1

3

Вам скорее всего необходимо делегировать событие для вновь создаваемых элементов.

$(selector).on("click", ".players", function() { // ваш скрипт });

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.