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
Post a Comment