...

View Full Version : getAttributeNode



Kor
12-28-2005, 09:23 AM
I want to check whether a certain element has attached a certain event. Maybe it is not the brightest ideea, but I tried to use getAttributeNode() method. Now I am confused by the way IE and Moz treat this method.

If:


<script type="text/javascript">
function check(id){
var obj = document.getElementById(id);
alert(obj.getAttributeNode('onMouseOver'))
}
</script>


IE shows me an object [object] while Moz shows me an attribute [object Att]

But if I use
obj.getAttributeNode('onMouseOver').nodeValue
Both show correctly the function triggered

Now that really confuses me, as I can not use a boolean to check whether an element has attached an event or not, because IE and Moz treat, as I have first said, getAttributeNode() in different manners.

Why so? Which of them is correct?

A1ien51
12-30-2005, 02:12 PM
why don't you try an object type of detection such as:



<div id="d1" onclick="alert('a')">a</div>
<div id="d2"></div>
<script type="text/javascript">
var elems = document.getElementsByTagName("div");
for(var i=0;i<elems.length;i++){
if(elems[i].onclick!=null)alert(elems[i].id);
}
</script>


Eric

jkd
12-30-2005, 07:21 PM
IE shows me an object [object] while Moz shows me an attribute [object Att]

And? Doesn't mean that they are different. Mozilla uses a public Attr() type to represent the object, while IE uses an private, internal type to do so. Doesn't mean that the properties and methods are different. As you said, the nodeValue property is the same on both.

However, why not just use getAttribute instead of getAttributeNode? You'll get an empty string or a string representing the attribute. Alternatively, you could even just use the hasAttribute() method, which returns a boolean reflecting the presence of the specified attribute.

Kor
01-03-2006, 09:11 AM
And? Doesn't mean that they are different. Mozilla uses a public Attr() type to represent the object, while IE uses an private, internal type to do so. Doesn't mean that the properties and methods are different. As you said, the nodeValue property is the same on both.
Yes, but the presence, as boolean, is different.


Alternatively, you could even just use the hasAttribute() method, which returns a boolean reflecting the presence of the specified attribute.
Yes, thanks, this is the best way.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum