[Javascript] List custom element properties in IE5/IE5.5?
Hakan M.
hakan at backbase.com
Mon Nov 24 11:20:00 CST 2003
Imagine the following tag, with the custom property:
<div id="myid" mycustom="thisvalue" width="30"> hello </div>
Now, I want a LIST of the attributes DEFINED ON THE TAG, including
custom attributes. I do not know any of the possible custom attributes
up front. In Mozilla and Internet Explorer 6, the following function works:
--
oElm = document.getElementById('myid');
var sProp, sVal, bSet;
var aAttribute = new Array();
for(var i=0; i < oElm.attributes.length; i++) {
sProp = oElm.attributes.item(i).nodeName;
sVal = oElm.attributes.item(i).nodeValue;
bSet = oElm.attributes.item(i).specified ? true : false;
if(bSet) {
aAttribute[sProp] = sVal;
}
}
--
Meaning that after I run the loop on my element, aAttribute contains an
array of properties defined on the element, and aAttribute['mycustom']
is 'thisvalue'.
In Internet Explorer 5.5, however, the custom properties exist in the
elements "all"-collection (element[PROPNAME]), but only as
element[PROPNAME] = VALUE, where PROPNAME is just a standard string
identifyer. Hence, there's no way for me to tell if the
element[PROPNAME] is a property, a custom property or if it's even
defined on the tag and not by IE (like element['onmouseover'],
element['class'] et cetera).
When I try a (slightly more 'friendly') version of the above script in
IE5/IE5.5 the "specified" attribute, among other things, returns 'false'
even if the property was indeed set on the element. IE5/IE5.5 can
SOMETIMES find ONE (of many) custom attributes, but in nine times out of
ten, the browser crashes badly after finding that first one.
Anybody ever did anything similar?
element.getAttributesOnElement would be a nice method. ;)
Regards,
Hakan
More information about the Javascript
mailing list