|
|||
Wie funktioniert nextSibling?
Hallo! Ich habe folgenden html-code (vereinfachtes Beispiel):
Code:
<div><img src="pic1" onmouseover="Over(this);"></div> <div style="display:none;"><img src="pic2"></div> Code:
function Over(imgElement) { var myparent = imgElement.parentNode; var mydiv = myparent.nextSibling; if (mydiv == NULL) alert("NULL"); else { alert(mydiv.tagName); mydiv.style.display = "none"; } } Geändert von wuschba (14.11.2007 um 13:32 Uhr) |
Sponsored Links |
Sponsored Links |
|
|||
Der IE erkennt den Texknoten nicht, daher noch in einer while-Schleife den nodeType Prüfen, also etwa so:
Code:
function Over(imgElement) { var myparent = imgElement.parentNode; var mydiv = myparent.nextSibling; while(mydiv.nodeType!=1){ mydiv=mydiv.nextSibling; } if( mydiv == undefined ) { alert("NULL"); } else { alert(mydiv.tagName); mydiv.style.display = "block"; }
__________________
Rechtschreibung und Grammatik beherrsche ich perfekt, ich wende sie nur nicht an Geändert von Ernie (14.11.2007 um 15:17 Uhr) Grund: zunächst zu Umständlich |
|
|
Ähnliche Themen | ||||
Thema | Autor | Forum | Antworten | Letzter Beitrag |
Mouseover funktioniert nicht (externe Methode) | blackhtml | CSS | 2 | 07.04.2009 17:49 |
Overflow hidden funktioniert im firefox nicht | Lena83 | CSS | 10 | 03.12.2008 18:18 |
Seltsam! "&" funktioniert - "&" nicht! | RollingStones | Javascript & Ajax | 4 | 22.01.2008 09:20 |
dtd und css in php funktioniert im IE nicht!!! | da-lick | CSS | 17 | 09.06.2007 15:44 |
min-width funktioniert lokal | andip | Javascript & Ajax | 3 | 06.06.2006 20:13 |