$('your_selector').removeAttr('checked') will also work, which personally
seems more intuitive to me.

--Erik


On 8/5/07, Marshall Salinger <[EMAIL PROTECTED]> wrote:
>
>  That is a strange find. I wouldn't have thought to test a different
> string outside of the html spec for setting it to checked. I guess any value
> as a string will return true. You can use
> $('your_selector').attr('checked',''); or attr('checked',false); as you
> stated, to uncheck the box.
>
>
> Mitchell Waite wrote:
>
>  Yes that's true it does, but so does $('your_selector').attr('checked','hi
> mom');
>
>
>
> And try unselecting it.
>
>
>
> *From:* jquery-en@googlegroups.com 
> [mailto:jquery-en@googlegroups.com<jquery-en@googlegroups.com>]
> *On Behalf Of *Marshall Salinger
> *Sent:* Sunday, August 05, 2007 4:06 PM
> *To:* jquery-en@googlegroups.com
> *Subject:* [jQuery] Re: Turning a checkbox on and off
>
>
>
> I am not sure I follow. $('your_selector').attr('checked','checked'); does
> set a checkbox to checked.
>
> -Marshall
>
> Mitchell Waite wrote:
>
> I thought the same about checking a checkbox but "checked" is not the
> right value, you have to use true and false.
>
>
>
> So like this:
>
>
>
> On
>
> $(checkbox).attr("checked", true);
>
>
>
> Off
>
> $(checkbox).attr("checked", false);
>
>
>
> I have no idea why you cant do $(checkbox).attr("checked", "checked");
>
>
>
> This also won't work
>
>
>
> if( $(checkbox).is(":checked") ) { alert("checked"); }
>
>
>
> Mitch
>
>
>
> *From:* jquery-en@googlegroups.com 
> [mailto:jquery-en@googlegroups.com<jquery-en@googlegroups.com>]
> *On Behalf Of *Ganeshji Marwaha
> *Sent:* Sunday, August 05, 2007 1:54 PM
> *To:* jquery-en@googlegroups.com
> *Subject:* [jQuery] Re: Turning a checkbox on and off
>
>
>
> To determine if a checkbox is checked, i would use if(
> $(checkbox).is(":checked") ) { alert("checked"); }
>
>
>
> To check a checkbox, $(checkbox).attr("checked", "checked");
>
>
>
> Both are untested, but let me know how it goes
>
>
>
> -GTG
>
>
>
> On 8/5/07, *Mitch* <[EMAIL PROTECTED]> wrote:
>
>
> How do you check and uncheck a checkbox from jQuery?
>
> And how do you determine if a checkbox has been checked or unchecked?
>
> I tried attr and css and none of them worked.
>
> Thanks
>
> Mitch
>
>
>
>
>
>
>

Reply via email to