Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery click not being recognized

Im creating a signup page for my website but it is not responding to a click. I have the jQuery in a seperate file called signup.js. I know it is linked properly because an alert works. Any help would be apreciated. Thanks

html:

<html>
    <head>

        <title>Sign Up</title>
        <script src="JS/jquery-3.1.1.min.js"></script>
        <script src="JS/signup.js"></script>
        <link rel="stylesheet" href="CSS/signup.css">
        <link rel="stylesheet" href="CSS/bootstrap.min.css">

    </head>

    <body>

        <div class="container">  

            <div class="jumbotron">

                <button id="signup-button">Sign Up</button>

            </div>    

        </div> 


    </body>

</html>

jQuery:

$("#signup-button").click(function() {
    alert("clicked");
});
like image 555
Rudi Thiel Avatar asked Mar 08 '26 23:03

Rudi Thiel


1 Answers

You are trying to get the element before loading the DOM element so it won't get attach the handler to the element since it's not present at that point. To make it works wrap it using document ready handler or move the script tag after the element in the markup.

$(document).ready(function(){
  $("#signup-button").click(function() {
    alert("clicked");
  });
});
like image 114
Pranav C Balan Avatar answered Mar 11 '26 13:03

Pranav C Balan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!