Add method onto a single jQuery node
<p>Say that I have two html nodes like this:</p>

<pre><code>&lt;div class='node a'&gt;one&lt;/div&gt;
&lt;input class='node b' value='two'&gt;
</code></pre>

<p>and I'd like to add a method for $('.node.a'), but not for node b. What I'd really like to do is something like this:</p>

<pre><code>$('.node.a').addMethod('val', function() {
  return $('.node.b').val();
});

alert($('.node.a').val()); // alerts 'two'
</code></pre>

<p>Clearly I don't want to override the 'val' method for every jQuery node. Is it possible to do this?</p>

<p><strong>* UPDATE *</strong></p>

<p>As per mgibsonbr's suggestion, I wrote a jQuery plugin to do this for me. Instead of using jQuery data method, I only run different functionality if the node in question is the one being called. This means that this form will not work for jquery lists that match multiple html nodes. Here it is:</p>

<pre><code>// overrides a method thats supposed to be called on a single node (a method like val)
$.fn.overrideNodeMethod = function(methodName, action) {
    var originalVal = $.fn[methodName];
    var thisNode = this;
    $.fn[methodName] = function() {
        if (this[0]==thisNode[0]) {
            return action.apply(this, arguments);
        } else {
            return originalVal.apply(this, arguments);
        }
    };
};
</code></pre>
