How to Handle Button Click Events in jQuery?
You have to put the event handler in the $(document).ready() event:
$(document).ready(function() {
$("#btnSubmit").click(function(){
alert("button");
});
});
$(document).ready(function(){
$('your selector').bind("click",function(){
// your statements;
});
// you can use the above or the one shown below
$('your selector').click(function(e){
e.preventDefault();
// your statements;
});
});
$('#btnSubmit').click(function(){
alert("button");
});
or
//Use this code if button is appended in the DOM
$(document).on('click','#btnSubmit',function(){
alert("button");
});
See documentation for more information:
https://api.jquery.com/click/
Try This:
$(document).on('click', '#btnClick', function(){
alert("button is clicked");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnClick">Click me</button>