javascript - How to wrap existing event handler without modifying "this"? -



javascript - How to wrap existing event handler without modifying "this"? -

i using existing code has form submit handler:

function ajaxformsubmit(e) { [...] var form = $(this); [...] }

to bind handler in view code have this:

$('myform').submit(ajaxformsubmit);

what want run other code before calling ajaxformsubmit this:

$('myform').submit(function(e) { dosomething(); ajaxformsubmit(e); });

the problem in ajaxformsubmit, phone call $(this) doesn't form element. best way accomplish this?

you need sure this gets called in right context.

$('myform').submit(function(e) { dosomething(); ajaxformsubmit.call(this, e); });

javascript jquery

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -