Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]wywoływanie tej samej funkcji z różnymi zmiennymi - uproszczenie zapisu
stellatus
post
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
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 9.10.2025 - 13:55