Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button Click in jQuery

I'm new to jQuery. I want to use a button click event to raise an alert box. This is my code, but it doesn't seem to work.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Jquery Basic</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                $('submit1').click(function() {
                    alert("JQuery Running!");
                )};
            });
        </script>
    </head>
    <body>
        <a>JQuery Test Page</a><br>
        <input id="submit1" type="button" value="Submit"/>
    </body>
</html>
like image 842
Sirakhil Avatar asked Oct 08 '13 09:10

Sirakhil


People also ask

How do you call a button click event in jQuery?

The click() is an inbuilt method in jQuery that starts the click event or attach a function to run when a click event occurs. Syntax: $(selector). click(function);

What is difference between click and Onclick in jQuery?

click() in that it has the ability to create delegated event handlers by passing a selector parameter, whereas . click() does not. When . on() is called without a selector parameter, it behaves exactly the same as .

What is Click () method?

The click() method simulates a mouse-click on an element. This method can be used to execute a click on an element as if the user manually clicked on it.

What is $() in jQuery?

In the first formulation listed above, jQuery() — which can also be written as $() — searches through the DOM for any elements that match the provided selector and creates a new jQuery object that references these elements: 1. $( "div.


2 Answers

You are missing the # from your id selector. Try this:

$(document).ready(function(){
    $('#submit1').click(function(){
        alert("JQuery Running!");
    });
});
like image 127
Rory McCrossan Avatar answered Sep 30 '22 23:09

Rory McCrossan


Answer already posted by @Rory, but you can also try this

$(document).ready(function(){
    $('#submit1').on('click',function(){
        alert("JQuery Running!");
    });
});
like image 25
Amit Avatar answered Sep 30 '22 23:09

Amit