1
I would like to click the button, open in a modal Bootstrap the contents of another page. I have the following code below:
<script src="js/jquery.min.js"></script>
<button class="btn btn-success" id="btnImprimir" title="Clique para imprimir sua carteira" data-toggle="modal"><i class="fas fa-print"></i> Imprimir</button>
<div class="modal drag" id="modalImprimir" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
<div class="modal-dialog">
<div>
<div id="tela">
</div>
</div>
</div>
</div>
<script>
$("button").on('click',"#btnImprimir", function(){
alert('aqui');
$.post('carteira-imprimir.php', function(retorno){
$("#modalImprimir").modal({ backdrop: 'static' });
$("#tela").html(retorno);
});
});
</script>
And the page wallet-print.php
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title" id="exampleModalLabel" style="font-weight: bold"><i class="fas fa-address-card"></i> CARTEIRA ESCOLAR</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Conteúdo
</div>
</div>
Only when clicking, it does not open the modal nor the Alert() I put for test. How do I correct this?
Your selector is incorrect. Instead of
$("button").on(...
should be$(document).on(...
– Sam
Hello Sam. Perfect!! It worked! Thank you so much again! If you want to put as an answer, I click accept as the correct answer.
– user24136