getElementById funktioniert nicht auf einem Knoten

In diesem einfachen Skript bekomme ich die Fehlermeldung "obj.parentNode.getElementById ist keine Funktion", und ich habe keine Ahnung, was falsch ist.

<script type="text/javascript">

        function dosomething (obj) {
         sibling=obj.parentNode.getElementById("2");
         alert(sibling.getAttribute("attr"));
        }

</script>

<body>
 <div>
  <a id="1" onclick="dosomething(this)">1</a>
  <a id="2" attr="some attribute">2</a>
 </div>
</body>

InformationsquelleAutor Ursus Russus | 2010-10-10

Schreibe einen Kommentar