Reputation: 1510
Need help if anyone know how it happens in IE5 and how to correct in IE11
I just started looking into an issue. There was an web application where they were using only in IE and the compatibility mode was IE5. Now I am migrating the compatibility mode to IE11 (Edge). I see the below line of code and it is working fine in IE5 compatibility, but in IE11 it is throwing undefined.
<td style='text-align: left;' class='isEditable-no' dataType='customerGciNo'>
...
javascript:
alert(oCell.dataType); -> output: customerGciNo -> in IE5
alert(oCell.dataType); -> output: undefined -> in IE11
Could you please help how to get it work in IE11 compatibility mode
Upvotes: 0
Views: 28
Reputation: 1074666
To get an attribute from an element, you use getAttribute
:
alert(oCell.getAttribute("dataType"));
The old code was relying on the attribute being automatically reflected as a property on the element. I didn't know IE5 did that; certainly no modern browser does.
Side note: Using custom attributes on elements without using the data-*
prefix is invalid according to spec. (It works, it's just invalid.) So you could change that to data-type="customerGciNo"
to make it valid, then use getAttribute("data-type")
. Modern browsers also support the dataSet
property which reflects data-*
attributes, and so you could read it with oCell.dataSet.type
.
Upvotes: 2