0

I have a JS code in my WebApp and it's supposed to be triggered when I click a anchor and in fact it is, but only if I also use with $(document).ready. If I use only the click event the script is not executed, but if I insert one more line in the JS file with $(document).ready the script is invoked as soon as the page load and also when I click the button. My intention in to call that script only when this particular button is clicked but I can't find a way to achieve this. Can you guys help?

<c:forEach items="${prontuario.atendimentos}" var="atendimento">
  <li> ${atendimento.preenchimentoModeloAtendimento} ${atendimento.dataAtendimento} ${atendimento.tipoDeAtendimento.custo}
   <a href="<c:url value="/prontuario/removerAtendimentoDoProntuario/${prontuario.prontuarioId}/${atendimento.atendimentoId}"></c:url>"><i class="fa fa-arrow-circle-o-down fa-2x"></i></a>
    <a id="aEditaAtendimento" href="<c:url value="/prontuario/editarAtendimento/${prontuario.prontuarioId}/${atendimento.atendimentoId}"></c:url>"><i class="fa fa-arrow-circle-o-down fa-2x"></i></a>
  </li>
</c:forEach>

var abreEdicaoAtendimento = function() {
  var idAtendimento = $('#idAtendimento').text();
  var botaoAbreModal = $('#btnEditarAtendimento');
  var campoIdPersistir = $('#atendimentoId');
  alert(idAtendimento);
  if (idAtendimento !== null) {
    campoIdPersistir.val(idAtendimento);
    botaoAbreModal.click();
  } else {
    alert('else');
  }
};
$('#aEditaAtendimento').click(abreEdicaoAtendimento);
$(document).ready(abreEdicaoAtendimento);
Barmar
  • 596,455
  • 48
  • 393
  • 495

0 Answers0