Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> innerHTML nie działa z getElementsByClassName
AboutMe
post 9.10.2018, 19:23:36
Post #1





Grupa: Zarejestrowani
Postów: 261
Pomógł: 0
Dołączył: 24.02.2008

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


Dlaczego poniższy kod działa gdy użyje się getElementById a nie działa z getElementsByClassName -> http://jsfiddle.net/n2ofsyua/

  1. document.getElementById('id-block').innerHTML += '<div id="new-block">xxx</div>';
  2. document.getElementsByClassName('class-block').innerHTML += '<div id="new-block">xxx</div>';


OK, już mam, trzeba użyć

Cytat
document.getElementsByClassName('class-block')[0].innerHTML += '<div id="new-block">xxx</div>';


Tylko jak zrobić żeby to działało na wielu elementach o nazwie class-block?

Ten post edytował AboutMe 9.10.2018, 19:23:47
Go to the top of the page
+Quote Post
trueblue
post 9.10.2018, 19:25:18
Post #2





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


Rozumiesz co zwraca metoda getElementsByClassName i dlaczego musiałeś dodać [0]?


--------------------
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 11:56