Saturday, May 23, 2015

Bind Unbind Events In JQuery javascript

Explanation:
In the form I have a button with id “btnsubmit”. Below is the code.

<input id="btnsubmit" type="button" value="Submit" />

My requirement is I need to bind a function to the onclick event  of the button and unbind it whenever it is notnecessary. To achieve this first define the function like the below.

var testingfn=function() {
//your code here
};


To bind the click event to the button(btnsubmit) below code is used

$('#btnsubmit').click(testingfn);
           
To unbind the click event to the button(btnsubmit ) below code is used


$('#btnsubmit').unbind("click");