On Jan 18, 11:23 am, Mathias Schäfer <[email protected]> wrote: > 2011/1/18 Diego Perini <[email protected]>: > > >> $('#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). > > I'm aware of the DOM properties vs. HTML attributes problem in general > but could you please elaborate the inconsistencies in this specific > case. What jQuery actually does here is elem['checked'] = true (cf.
Correct ! That doesn't set the element attribute as the name implies, that will just set the so named element property value. To kind of understand this point, try to think about attributes being "strings".- > line 1749 of jQuery 1.4.4) and elem.checked === true (cf. line 3573). > That's the recommended way, isn't it? > Yes, that's good enough ! Also, only certain control elements implements live properties like that. So extra checks will be necessary to avoid false positives (user code setting same name property on elements that do not implement those interfaces). -- Diego > Regards > Mathias -- 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]
