On Jan 18, 2011, at 12:15 PM, Miller Medeiros wrote:

> 
> On Tue, Jan 18, 2011 at 9:47 AM, Diego Perini <[email protected]> wrote:
> 
>    $('#my-check-box').attr('checked', true);
> 
> will confuse users into believe that "false" in the above statement is
> needed to achieve the opposite effect of unchecking the element
> attribute, which is not the case. Instead a "removeAttr()" will be
> needed to achieve that effect (with UI live attributes like
> "checked").
> 
> 
> if you pass false to the checked attribute it will uncheck it.. (it probably 
> calls removeAttr internally)

What i think it does (actually from making several tests)
when you create a checkbox and get the checked property you obtain false
if you click on it and ask for checked attribute you obtain true

now passing any JavaScript falsy value to checked will uncheck the checkbox and 
getting later the value you will get a false

same occurs when passing any truthy  value you will get true when getting the 
value later

removing the checked attribute has no effect on the input

so from this i would recommend to use true or false for checked attribute to 
keep things clear

correct me if i am wrong pls.

> 
>  
> Thus the name ".attr()" is itself misplaced and the documentation
> misguiding people approaching Javascript and the DOM (read the
> comments there).
> 
> 
> Yes, many jQuery methods have weird naming and doesn't match the standard 
> ones.. even things like "each()", "map()" doesn't behave like the native 
> ones.. (I always have to go back to the documentation because of things like 
> that) and yes, the comments usually have a bunch of bad practices.
> 
>  
>    $('#my-check-box').is(':checked');
> 
> this will not check the attribute value either, it will check the
> property value of the element (at least it should, not verified in
> jQuery).
> 
> To check for an attribute value in jQuery one must use the attribute
> selector, like this (faster too):
> 
>    $('#my-check-box[checked]');
> 
> this is as in CSS2.1 standard and would return correct results for the
> element "checked" attribute.
> 
> The ":checked" pseudo-class will check the live DOM property value of
> the elements, not their attributes.
> 
> about the checked selector:  http://api.jquery.com/checked-selector/  -  it 
> is supposed to work just fine for checkboxes and radio buttons... probably 
> they convert it to an attribute selector internally...
> 
> jQuery is nothing about following the standards or best-practices and I don't 
> like that either.. but most of the times that I use jQuery is because I'm 
> working with someone that is used to it, so doing it on the "jQuery way" 
> makes more sense in this context.. future developers will understand what is 
> going on and if they don't there is documentation available about it..
> 
> I agree that jQuery is misleading in some aspects but I couldn't see a 
> context where the code that I provided wouldn't work.. I thought it was some 
> known bug related with this specific feature. But your points were valuable 
> anyways, thanks.
> 
> -- 
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
>  
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
>  
> To unsubscribe from this group, send email to
> [email protected]

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to