/    Sign up×
Community /Pin to ProfileBookmark

getAttribute() returning odd value for IE

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″>[/code]

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 {
….
}
}
[/code]

For some reason, in IE only, when the nodeType attribute does not exist, the value returned by the call

[code]elem.getAttribute(“nodeType”)[/code]

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?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@steelersfan88Apr 14.2004 — Ie probably has different support for this. Do a webs search, I woudl recommend, to find the its support for nodeType attribute ?
Copy linkTweet thisAlerts:
@wood_tahauthorApr 14.2004 — Thank you very much, you got me thinking in the right direction.... I didn't officially confirm it, but once I changed the name of the attribute from nodeType to nodeTypeName, all was working as it should.

If I remember correctly, I believe that IE makes all of an element's attributes available to a script, whether they are declared inline in the element's code or not, whereas the Mozilla browsers only make those attributes declared inline in the element's code available to scripts.

If that is true, then there must be a nodeType attribute that already exists, and I was getting its value.

Thanks again for pointing me in the right direction!
Copy linkTweet thisAlerts:
@steelersfan88Apr 14.2004 — well I am glad to help out, and not hesitant to admit that what I provided was to be a start. The fact you got it working is great ?
Copy linkTweet thisAlerts:
@fredmvApr 14.2004 — [i]Originally posted by wood_tah [/i]

[B]If I remember correctly, I believe that IE makes all of an element's attributes available to a script, whether they are declared inline in the element's code or not, whereas the Mozilla browsers only make those attributes declared inline in the element's code available to scripts.[/B][/QUOTE]
That's somewhat accruate (to a degree) though IE's implementation is incorrect; [url=http://forums.webdeveloper.com/showthread.php?s=&threadid=32193]this thread[/url] touches upon this further.
×

Success!

Help @wood_tah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...