Button not activating function in Javascript

Asked

Viewed 23 times

0

The close button works perfectly while the send button does not trigger the routine in any way.

$("#incluirItensNoGrid").on('click', function(){
  alert("Hello World!");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal-footer d-flex justify-content-center">
  <button 
    class="btn btn-success" 
    id="incluirItensNoGrid()">Enviar
  </button>
  <button 
    class="btn btn-danger" 
    class="close" 
    data-dismiss="modal" 
    aria-label="Close">Cancelar
  </button>
</div>

1 answer

1


The button id, change to id="incluirItensNoGrid" removing the () at the end, because you are setting the property ID and not calling a function...

Staying:

<div class="modal-footer d-flex justify-content-center">
<button 
    class="btn btn-success" 
    id="incluirItensNoGrid">Enviar
</button>
<button 
    class="btn btn-danger" 
    class="close" 
    data-dismiss="modal" 
    aria-label="Close">Cancelar
</button>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

<script type="text/javascript">
$("#incluirItensNoGrid").on('click', function(){
    alert("Hello World!");
});
</script>
  • Or change the dial to $("#incluirItensNoGrid()"), but the first option is better

  • Yes. I’ve done it and it worked! Thank you, buddy!

  • I made the first that arrow the id name correctly. Again, thank you very much Mirak!

  • Right?! Then mark as resolved... : P

  • Yes, I marked as resolved! Congratulations and thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.