How do I add a function to an element via jQuery?
<p>I want to do something like this:</p>

<pre><code>$('.dynamicHtmlForm').validate = function() {
  return true;
}

$('.dynamicHtmlForm .saveButton').click(function() {
  if (!$(this).closest('.dynamicHtmlForm').validate()) {
    return false;
  }

  return true;
});
</code></pre>

<p>And then when I have a form of class dynamicHtmlForm, I want to be able to provide a custom validate() function:</p>

<pre><code>$('#myDynamicHtmlForm').validate = function() {
  // do some validation

  if (there are errors) {
    return false;
  }

  return true;
}
</code></pre>

<p>But I get this when I do this:</p>

<pre><code>$(this).closest(".dynamicHtmlForm").validate is not a function
</code></pre>

<p>Is what I've described even possible? If so, what am I doing wrong?</p>
