Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z getElementsByName
PKua
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 28.04.2013

Ostrzeżenie: (0%)
-----


Witam,
mam taką funkcję:
Kod
function userdetails (id)
            {
                var detailrows = id.parent.parent.parent.parent.getElementsByName('details');
                var display = detailrows[0].style.display == 'none' ? '' : 'none';
                id.innerHTML = display == '' ? 'Mniej szczegółów' : 'Więcej szczegółów';
                for (var i = 0; i < detailrows.length; i++)
                    detailrows[i].style.display = display;
            }


i jak ją wywołuje link w stopce tabeli (href="java script:userdetails(this)" - bez spacji, nie wiem dlaczego sama się dodaje) to wywala błąd, że nie ma metody "parent". Wygląda na to, że this nie zwraca dobrego wskaźnika do obiektu. OCB? Próbowałem także w onclick - to samo.

Ten post edytował PKua 8.05.2013, 14:21:58
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
PrinceOfPersia
post
Post #2





Grupa: Zarejestrowani
Postów: 717
Pomógł: 120
Dołączył: 18.04.2009

Ostrzeżenie: (0%)
-----


Cytat
id.parent.parent.parent.parent.getElementsByName('details');

bo to nie jest zbyt elegancki kod. Lepiej pomyśl i napisz co chcesz zrobić, gdzie w twojej strukturze HTML masz element "details"?


Ten post edytował PrinceOfPersia 8.05.2013, 15:36:16
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 23:35