Getting checkboxes to maintain checked state on click
<p>I've tried various methods to get my checkboxes to be checked upon a click. </p>

<p>The following works on document ready:</p>

<pre><code>$('input[name=foo]').attr("checked","checked");
</code></pre>

<p>However as soon as I surround it with a click event the checkboxes won't maintain checked state. On the click they check (as they should) and then immediately uncheck.</p>

<pre><code>$("#selectall").click(function(){
$('input[name=foo]').attr("checked","checked");
});
</code></pre>

<p>My HTML:</p>

<pre><code>&lt;form id="frm1"&gt;
&lt;input type="checkbox" name="foo" value="bar" /&gt;
&lt;/form&gt;
</code></pre>
