Skip to main content
WolfShade
Brainiac
April 25, 2018
Answered

jQuery: Weird issue with .on('click')

  • April 25, 2018
  • 1 reply
  • 596 views

Hello, all,

I've got a weird issue with a jQuery .on('click') call.  It won't even trigger an alert.  The following is part of a Bootstrap v4 modal.

<button class="btn btn-primary" id="submitBtn" name="submitBtn">Submit</button>

<button class="btn btn-secondary" id="closeBtn" name="closeBtn">Close</button>

<!-- Here is where I'm loading jQuery, Bootstrap, and popper.js -->

<script type="text/javascript">

     $('#submitBtn').on('click',function(){

          alert("I have been clicked.");

          });

</script>

When I open the modal and click the submit button, I get no alert.  jQuery is loading properly.  Nothing is appearing in the error console.  Any thoughts?

V/r,

^ _ ^

    This topic has been closed for replies.
    Correct answer WolfShade

    Nevermind.  Figured it out.  For some reason I am not allowed to use "submitBtn" as the name or ID of an element.

    As soon as I changed it to "submitForm", it works.

    Is this another quirk of Bootstrap or popper.js?

    V/r,

    ^ _ ^

    1 reply

    WolfShade
    WolfShadeAuthorCorrect answer
    Brainiac
    April 25, 2018

    Nevermind.  Figured it out.  For some reason I am not allowed to use "submitBtn" as the name or ID of an element.

    As soon as I changed it to "submitForm", it works.

    Is this another quirk of Bootstrap or popper.js?

    V/r,

    ^ _ ^

    Brainiac
    April 25, 2018

    WolfShade  wrote

    Is this another quirk of Bootstrap or popper.js?

    V/r,

    ^ _ ^

    Have you got an instance of the id 'submitBtn' somewhere else in your code? If not then it should work.

    WolfShade
    WolfShadeAuthor
    Brainiac
    April 25, 2018

    I always name my submit buttons "submitBtn", so I don't know why it isn't working in this one instance.  But, then, this is the first time I've ever used Bootstrap.  I've got another form that will eventually be put in place (actually, now that I think of it, there will be two more), so I can try it, again, later.  But re-naming my submit button did the trick.

    It's just weird.

    V/r,

    ^ _ ^