Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    Question getAttributeNode

    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:
    PHP Code:
    <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?
    Last edited by Kor; 12-28-2005 at 12:27 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    why don't you try an object type of detection such as:

    Code:
    <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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by Kor
    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.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by jkd
    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.

    Quote Originally Posted by jkd
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •