click jquery call not working on button click

I am trying to write a simple code as follows:

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" />
    <script>
        $("#submitQuery").click(function() {
            alert("Hola!!");
        });
    </script>
    </head>
    <body>
        <label for="geo_location"> Enter location here: </label>
        <input id="geo_location" type="text" name="geo_location" required />
        <button id="submitQuery">Find out</button>
        <div id="test"></div>
    </body>
</html>

However, clicking the button doesn't do anything. Where am I wrong here?

Answers 1

  • <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" /> </script>
    <script>
        $(function(){
             $("#submitQuery").click(function() {
                 alert("Hola!");
             });
        });
    </script>
    

    try this...you miss the ready function..


Related Articles