you can also check the W3C DOM spec at http://www.w3.org/TR/html401/interact/forms.html#adef-checked
Attribute definitions .... checked [CI] When the type attribute has the value "radio" or "checkbox", this boolean attribute specifies that the button is on. User agents must ignore this attribute for other control types. also check the interface for this element at http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-6043025 nterface HTMLInputElement : HTMLElement { attribute DOMString defaultValue; attribute boolean defaultChecked; readonly attribute HTMLFormElement form; attribute DOMString accept; attribute DOMString accessKey; attribute DOMString align; attribute DOMString alt; attribute boolean checked; attribute boolean disabled; attribute long maxLength; attribute DOMString name; attribute boolean readOnly; // Modified in DOM Level 2: attribute unsigned long size; attribute DOMString src; attribute long tabIndex; // Modified in DOM Level 2: attribute DOMString type; attribute DOMString useMap; attribute DOMString value; I did not see any changes on DOM leve 3 so this must still apply On Jan 18, 2011, at 2:04 PM, Garrett Smith wrote: > On 1/17/11, Miller Medeiros <[email protected]> wrote: >> On Mon, Jan 17, 2011 at 10:54 PM, Diego Perini >> <[email protected]>wrote: >> >>> On Mon, Jan 17, 2011 at 11:52 PM, Miller Medeiros >>> <[email protected]> wrote: >>>>> >>>> $('#my-check-box').attr('checked', true); -> should work cross browser >>> if >>>> it is a checkbox. >>>> >>>> and you can check if a checkbox is checked by using >>>> `$('#my-check-box').is(':checked')`... >>>> >>> >>> these two $() statements alone deserve a long chapter by themselves to >>> exactly explain all the inconsistencies that may arise by using them >>> together (probably even for checkboxes). There is also a problem with >>> mixing strings and booleans to consider in your example (or in jQuery >>> anyway). >>> >>> Comparing values obtained by direct DOM properties access >>> (pseudo-selector) with values obtained by accessing HTML attributes >>> through getter/setter in that way is scary at best (maybe worth a >>> digest in JSMentors). >>> >>> >> I would like to know the reason besides the fact that I passed `true` >> instead of 'checked' - which I believe works just fine.. - and used >> `is(':checked')` instead of `attr('checked')` - which I agree is kinda >> weird. >> >> I have no idea how jQuery handles those things internally, but depending on >> how the `is(':checked')` is implemented there shouldn't be any >> inconsistencies (if it really checks the proper attribute instead of doing a >> selector query..). >> > DOn't know what you mean. > > The important thing to remember: Attributes != properties. > > el.getAttribute("checked"); // attribute value. > el.checked; // property value. > > In most cases you'll want the property value, so just use that. A > wrapper that tries to abstract reading all attributes or all > properties from every element in all browsers will be complicated and > probably have problems in some cases. > -- > Garrett > > -- > 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]
