Re: Accessing Form attributes instead of elements

RobG
Mon, 24 Sep 2007 13:50:20 -0000

On Sep 24, 5:33 pm, Thomas Fuchs <tho...-9D208sng4xU@public.gmane.org>
wrote:
> Seems that these are bugs. Can you whip up some failing unit tests
> for this?

I stand corrected on the checked attribute, when it is not set on IE
readAttribute returns null, as it should.  However when set, IE
returns ''checked'' whereas other browsers return an empty
string.  The
significance that will vary, but is likely more significant when
serialising forms.

For those attributes that return a boolean (checked, selected,
readonly, etc.), it is better to use dot properties ($(id).checked
which seems to return a boolean in all browsers) rather than attempt
to use either getAttribute or the attributes object.

Anyhow, as for test cases, any attribute that takes a string value
should do - name, id, value...










 var t = [];
 [

[''f0'',''name''],[''i0'',''name'']

,[''i1'',''checked''],[''i2'',''checked'']

,[''i3'',''value''],[''i4'',''value'']
 ].each(function (a){
   var x = $(a[0]).readAttribute(a[1]);
   t.push( a[1] + '': '' + typeof x + '' : '' +
x);
 });

 alert(t.join(''\n''));




--
Rob