On Aug 6, 5:40 am, "Erik Beeson" <[EMAIL PROTECTED]> wrote:
> $('your_selector').removeAttr('checked') will also work, which personally
> seems more intuitive to me.
>
> --Erik

This, indeed seems "more" correct, as the w3c states:
"A switch is "on" when the control element's checked attribute is
set..."

They don't specify set to _what_.  (This is a I'd rather unset the
attribute than set it to 'false'.  This is the method recommended by
David Flanagan in his <a href="http://safari.oreilly.com/
0596101996">Definitive Guide</a>, I believe.
-Troy

>
> 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:* [email protected] 
> > [mailto:[email protected]<[email protected]>]
> > *On Behalf Of *Marshall Salinger
> > *Sent:* Sunday, August 05, 2007 4:06 PM
> > *To:* [email protected]
> > *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:* [email protected] 
> > [mailto:[email protected]<[email protected]>]
> > *On Behalf Of *Ganeshji Marwaha
> > *Sent:* Sunday, August 05, 2007 1:54 PM
> > *To:* [email protected]
> > *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