How To Toggle All Checboxes With JQuery
<p>I have a table whose values are generated dynamically with PHP.  Each row in the table has a checkbox.  In the table is a header column, that has a "Accept All" button.</p>

<p>When a user clicks the "Accept All" button, all select boxes are checked.  However, I want to add a toggle-like functionality:  if no boxes are checked, then pressing the button selects all; if all boxes are checked, then pressing the button would unselect all.</p>

<p>Here's my JQuery code for select all:</p>

<pre><code>//Approves all
$('#approve_all_questions').click(function () {
    $("INPUT[type='checkbox']").attr('checked', true);
});
</code></pre>

<p>I'm having trouble getting it to toggle correctly.  I've tried this:</p>

<pre><code>//Toggle
$('#approve_all_questions').click(function () {

    if($("INPUT[type='checkbox']").attr('checked', true))
    {
        $("INPUT[type='checkbox']").attr('checked', false);
    }
    else
    {
        $("INPUT[type='checkbox']").attr('checked', true);
    }
  });
</code></pre>

<p>But that doesn't work.</p>

<p>TIA.</p>
