Javascript this in jQuery -


i saw old code had:

<input type="submit" name="submit" onsubmit="somefunction(this)" /> 

i jquery'ing script, how pure javascript (this) object in jquery?

$("input[name=submit]").click(function() {   somefunction(// ?? $(this) ); }); 

thanks!

you can use this, refers clicked object, true jquery event handler:

$("input[name=submit]").submit(function() {   somefunction(this); }); 

or, better use this inside function, it's just:

$("input[name=submit]").submit(somefunction); 

this won't cover when it's not submitted via button though, better @ <form> level or via .live() if it's dynamic. note doing this, it'll change this refer <form> instead of <input>, depending on function may need adjustments that.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -