J
Jeff Bigham
Hi,
I'm trying to write an equivalent to the hasAttribute method that will
work with IE 6 and 7. IE 8 finally has this method built in.
There is supposed to be a way to do this using the 'specified'
property of the attribute, but it doesn't always work.
For instance, consider the following code:
function test() {
var intest = document.getElementById('in_test');
alert(intest.getAttribute('type') + " " +
intest.attributes['type'].specified + " " + intest.type);
}
....
<input id='in_test' type="text"></input>
....
Calling test() alerts "text false text"
I think this is because IE 6/7 confuses user-defined attributes and
its own DOM properties. Although, since both say that type is equal
to "text", I have no idea why I'm getting false here.
In other cases, IE requires odd workarounds. Like, you set the
className instead of class attribute to set the class attribute. Is
there something similar going on here? I tried 'typeName' but that
didnt' work. If that's the problem, does anyone know where I can find
a comprehensive list of all such name changes?
Or, just in general, a reasonable way to tell if the user has
specified an attribute.
Thanks,
Jeff
I'm trying to write an equivalent to the hasAttribute method that will
work with IE 6 and 7. IE 8 finally has this method built in.
There is supposed to be a way to do this using the 'specified'
property of the attribute, but it doesn't always work.
For instance, consider the following code:
function test() {
var intest = document.getElementById('in_test');
alert(intest.getAttribute('type') + " " +
intest.attributes['type'].specified + " " + intest.type);
}
....
<input id='in_test' type="text"></input>
....
Calling test() alerts "text false text"
I think this is because IE 6/7 confuses user-defined attributes and
its own DOM properties. Although, since both say that type is equal
to "text", I have no idea why I'm getting false here.
In other cases, IE requires odd workarounds. Like, you set the
className instead of class attribute to set the class attribute. Is
there something similar going on here? I tried 'typeName' but that
didnt' work. If that's the problem, does anyone know where I can find
a comprehensive list of all such name changes?
Or, just in general, a reasonable way to tell if the user has
specified an attribute.
Thanks,
Jeff