Get the element triggering an onclick event in jquery?
<p>I have a form where i've replaced the submit button with an input (with type=button) with an onclick which calls an existing function:</p>

<pre><code>&lt;form accept-charset="UTF-8" action="/admin/message_campaigns" class="new_message_campaign" id="new_message_campaign" method="post"&gt;
  &lt;!-- some fields --&gt;
      &lt;input onclick="confirmSubmit();" type="button" value="Send" /&gt;
&lt;/form&gt;
</code></pre>

<p>In the confirmSubmit, i'd like to be able to dynamically get the form object (to submit it), instead of having to hardcode the form's id, or pass it as part of the call to confirmSubmit().  I'd have thought that i could do this by first getting the dom element that was clicked on, ie something like this:</p>

<pre><code>var form = $(this).parents("form");
</code></pre>

<p>where $(this) is the object that called the function, ie the input with the onclick.  This doesn't work though.  I think it <em>would</em> work if i'd set it up with the <code>.click(function(){</code> syntax.  Can i get the element that called the function in a different way?</p>

<p>EDIT - got the answer from @claudio below, for clarity here's the complete function and call:</p>

<pre><code>&lt;form accept-charset="UTF-8" action="/admin/message_campaigns" class="new_message_campaign" id="new_message_campaign" method="post"&gt;
  &lt;!-- some fields --&gt;
      &lt;input onclick="confirmSubmit($(this));" type="button" value="Send" /&gt;
&lt;/form&gt;
</code></pre>

<p>and the function itself.  Note that 'jConfirm' is a method of the jquery-alerts plugin (http://abeautifulsite.net/blog/2008/12/jquery-alert-dialogs/) but that's not really relevant to this question - the key thing was just to get the form object, not what's subsequently done with it:</p>

<pre><code>function confirmSubmit(caller) {
  var form = caller.parents("form");
  jConfirm('Are you sure?', 'Please Confirm', function(result){
    if (result) {
      form.submit();
    } else {
      return false;
    }
  });
}
</code></pre>
