The best way to generalise a code for toggling the disabled attribute
<p>The following code (*) for toggling the disabled attribute beetween two buttons works and you can check it at <a href="http://jsfiddle.net/cNSVX/3/" rel="nofollow">http://jsfiddle.net/cNSVX/3/</a>.</p>

<p>I was wondering what is the best way to generalise this code in order to attach this behaviour to a couple of buttons.<br>
Something like the following.   </p>

<pre><code>body.onload(togglingButton(elem1, elem2));
</code></pre>

<hr>

<pre><code>$('#filterOpened').click(function() {
    $('#filterOpened').attr('disabled', 'disabled');
    $('#filterClosed').removeAttr('disabled');
});

$('#filterClosed').click(function() {
    $('#filterClosed').attr('disabled', 'disabled');
    $('#filterOpened').removeAttr('disabled');
});

function togglingButton (elem1, elem2) {
    if (elem2.attr('disabled')) {
        elem1.attr('disabled', 'disabled');
        elem2.removeAttr('disabled');
   } else {
        elem2.attr('disabled', 'disabled');
        elem1.removeAttr('disabled');
   } 
};
​
</code></pre>
