[jQuery] Proper method to check checkbox state
Hello everyone,
I was wondering what the "proper" way to check if a checkbox is checked is using jquery?
I've run into two methods... both of which appear to work fine in IE,FF,Chrome and safari.
<a href="http://jsbin.com/ifoka/edit">http://jsbin.com/ifoka/edit</a>
Assuming that I have two checkboxes, one with an id of test1 and one with an id of test2, i used these two methods:
<pre><code class="javascript"><span class="method">$</span>('<span class="selector">#test1</span>').<span class="method">is</span>(<span class="string">":checked"</span>)
<span class="method">$</span>('<span class="selector">#test2</span>').<span class="method">attr</span>(<span class="string">"checked"</span>)</code></pre>
Which method is better? Or is there a different way which is even more correct?
Thanks,
Matt