Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  14] [ 3]  / answers: 1 / hits: 19770  / 15 Years ago, wed, april 29, 2009, 12:00:00

I try to answer this question a few minutes ago and prepared this example for myself :



<script>
function trialMethod()
{
alert('On Submit Run!'); return true;
}
function trialMethod2()
{
alert('On Submit Run trialMethod2!'); return true;
}
</script>

<form id=aspnetForm onsubmit=trialMethod();>
<input type=submit>
</form>


Why the first unbind doesn't work :



<input type=button id=btnTrial1 value=UNBIND 1 
onclick=$('#aspnetForm').unbind('submit', trialMethod);>


But this one works for the trialMethod2 method :



<input type=button id=btnTrial2 value=UNBIND 2 
onclick=$('#aspnetForm').bind('submit', trialMethod2).unbind('submit', trialMethod2);>

More From » jquery

 Answers
33

The first unbind scenario doesn't work, because of jQuery's event model. jQuery stores every event handler function in an array that you can access via $(#foo).data('events'). The unbind function looks just for given function in this array. So, you can only unbind() event handlers that were added with bind()


[#99630] Thursday, April 23, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jamir

Total Points: 736
Total Questions: 97
Total Answers: 101

Location: Cayman Islands
Member since Fri, Mar 4, 2022
2 Years ago
;