I have a piece of code where I am using a custom attribute to hold additional data that is needed in a script. To retrieve that data, I am using getAttribute() in my script. An example of my code is below
[code=php]<a id=”nt:base” class=”selected” href=”#” onclick=”setSelectedNode(‘nt:base’); ntmGetProperties(this);” objectID=”0″>
A portion of my ntmGetProperties() method is shown below:
[code=php]
function ntmGetProperties(elem) {
var id = elem.id;
var objID = elem.getAttribute(“objectID”);
var nodeType = elem.getAttribute(“nodeType”);
var form = document.getElementById(“getNTMPropsForm”);
if (isEmpty(nodeType)) {
form.nodeType.value = id;
} else {
….
}
}
For some reason, in IE only, when the nodeType attribute does not exist, the value returned by the call
[code]elem.getAttribute(“nodeType”)
is 1.
Netscape, Mozilla, and Firefox all return null (as I would expect). As a result, the else condition gets executed when it should not.
Does anyone have any idea why IE returns 1, instead of null?