Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
How to add transition or fade-in effect to dynamically added field

I have input section with add/delete button, that adds extra input fields. I am trying to get input field appear with a transition effect instead of popping up instantly.

I tried to use transition but it didn't helped. Is it possible to do it via pure CSS?

Code

var i = 1;

$('#add_patient').click(function() {
  i++;
  $('#tbl_patient').append('<tr id="row' + i + '" class="dynamic-added">\
  <td>\
     <input type="text" id="patient' + i + '" name="patient" placeholder="Patient Name" required>\
  </td>\
  <td>\
     <button class="btn_remove" type="button" name="remove" id="' + i + '">--</button>\
  </td>\
</tr>');
});

$(document).on('click', '.btn_remove', function() {
  var button_id = $(this).attr("id");
  $('#row' + button_id + '').remove();
});
td {
  transition: 0.5s ease 1s;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="tbl_patient">
  <thead>
    <tr>
      <th colspan="2" class="uk-text-center">Patient</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <input type="text" id="patient" name="patient" placeholder="Patient Name">
      </td>
      <td>
        <button type="button" name="add_patient" id="add_patient">+</button>
      </td>
    </tr>
  </tbody>
</table>

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I don't use jQuery so had to use a little vanilla Javascript but essentially the transition is applied to the table-row and uses opacity from 0 - 1 to create the fade-in effect.

var i = 1;

$('#add_patient').click(function() {
  i++;
  $('#tbl_patient').append('<tr id="row' + i + '" class="dynamic-added hidden">\
  <td>\
     <input type="text" id="patient' + i + '" name="patient" placeholder="Patient Name" required>\
  </td>\
  <td>\
     <button class="btn_remove" type="button" name="remove" id="' + i + '">--</button>\
  </td>\
</tr>');

setTimeout(()=>{
  document.querySelector('tr.hidden:last-of-type').classList.remove('hidden');
},100);
});

$(document).on('click', '.btn_remove', function() {
  var button_id = $(this).attr("id");
    $('#row' + button_id).remove();
});
tr{
  transition:0.5s ease-in-out all;
  opacity:1;
}
.hidden{
  opacity:0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="tbl_patient">
  <thead>
    <tr>
      <th colspan="2" class="uk-text-center">Patient</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <input type="text" id="patient" name="patient" placeholder="Patient Name">
      </td>
      <td>
        <button type="button" name="add_patient" id="add_patient">+</button>
      </td>
    </tr>
  </tbody>
</table>

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda