Is there a better way to this Javascript code
<p>I have very easy JavaScript/CoffeSscript knowledge. I'm wondering if there's a better way to bind the placing the <code>active</code> class only when <code>tableContentsPane</code> is opened. </p>

<pre><code>$(document).ready -&gt;
  $('#tableContents').click -&gt; 
    $('#tableContentsPane').toggle();
    $("#tableContents").addClass "active" if $("#tableContentsPane").is(":visible")
    $("#tableContents").removeClass "active" if $("#tableContentsPane").is(":hidden")

  $('#tableContentsPane a').click -&gt; 
    $('#tableContentsPane').toggle();
    $("#tableContents").removeClass "active" if $("#tableContentsPane").is(":hidden")
</code></pre>
