I saw some old code that had:
<input type="submit" name="submit" onsubmit="somefunction(this)" />
I was jQuery’ing the script, how do I get the pure javascript (this) object in jQuery?
$("input[name=submit]").click(function() {
somefunction(// ?? is it $(this) );
});
Thanks!
You can just use
this, it refers to the clicked object, this is true for any jQuery event handler:Or, better would be to use
thisinside the function, then it’s just:This won’t cover when it’s not submitted via the button though, better to do it at the
<form>level or via.live()if it’s dynamic. Note that by doing this, it’ll changethisto refer to the<form>instead of the<input>, depending on your function you may need adjustments for that.