Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]wywoływanie tej samej funkcji z różnymi zmiennymi - uproszczenie zapisu
stellatus
post 26.04.2020, 21:30:47
Post #1





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 9.03.2017

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


Kod
function removeIcons(x) {
  x.forEach(function (element) {
  element.remove()
  })
}

removeIcons(document.querySelectorAll(".film-icon"))
removeIcons(document.querySelectorAll(".music-icon"))
removeIcons(document.querySelectorAll(".book-icon"))
removeIcons(document.querySelectorAll(".software-icon"))
removeIcons(document.querySelectorAll(".smile-icon"))
removeIcons(document.querySelectorAll(".article-icon"))


Da się to zapisać prościej? Nazwa wywoływanej wielokrotnie funkcji nie musi się chyba powtarzać, prawda?
Go to the top of the page
+Quote Post

Posty w temacie


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: 21.06.2025 - 02:21