On Jan 18, 2011, at 6:31 PM, Garrett Smith wrote:

> On 1/18/11, fernando trasvina <[email protected]> wrote:
>> 
>> 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..).
>> 
>> because any truthy value passed checks the input so 'checked' is truthy
>> 
>> Also jQuery works fine setting the value via .attr method and sets the
>> correct value in the correct object and property
>> 
> I've already explained why that is false. And there are a ton more
> explanations on c.l.js.
> 
> An input's `checked attribute is not the same as its property.
> 
> again:
>  inp.checked; // property
>  inp.getAttribute("checked"); // attribute value -- must be a string!

run this with the jquery api and you will see that running .attr('checked', 
true) does not sets the attribute. sets the property
so it works as it should.

This has nothing to do with the difference between properties and attributes 
for an element. you are correct that it is not the same
but jquery handles this well

also if you do inp.checked = 'of course'
inp.checked //true

which it is still not in conflict with what you are saying

and the other thing is that the property is specified as boolean.

> 
> The checked attribute, as with any attribute, must be a string value
> or null. jQuery returning values that are not strings for `attr` means
> that it is not returning attribute values. And it isn't. And not only
> doesn't it, it returns property values.
> 
> It's really old news. HTH. If not, maybe RobG or Diego or somebody can
> explain again. I feel like I'm not getting through.
> 
> And I see jQuery continues to contribute to confusion about properties
> and attributes.
> -- 
> 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]

Reply via email to