bootstrap modal window does not close

1

My modal window does not close when I click on the close button, previously it worked correctly and now it does not close anymore,

this is the html code of the close button:

<div id="modalContractCandidatesPre" class="modal fade" data-keyboard="false" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content"> <!-- div que continen toda la ventana modal -->
                <div class="modal-header"> <!-- Header -->
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

and the footer

<div class="modal-footer"> <!-- Footer -->
                    <button id="saveContractCandidatePre" type="button" class="btn btn-success">
                        <i class="fa fa-floppy-o" aria-hidden="true"></i> Guardar
                    </button>

                    <button type="button" class="btn btn-danger" data-dismiss="modal">
                        <i class="fa fa-times" aria-hidden="true"></i> Cerrar
                    </button>
                </div>
    
asked by Alejandro.C 23.11.2017 в 23:53
source

1 answer

2

It's strange that you do not close the modal with the button passing it the attribute data-dismiss="modal" but that's not a problem since we can "force" the modality to close by means of JavaScript:

$(".cerrarModal").click(function(){
  $("#modalContractCandidatesPre").modal('hide')
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#modalContractCandidatesPre">
  Abrir modal
</button>

<!-- Modal -->
<div class="modal fade" id="modalContractCandidatesPre" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close cerrarModal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Título modal</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default cerrarModal">Cerrar</button>
      </div>
    </div>
  </div>
</div>
    
answered by 24.11.2017 / 14:31
source