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"))
How can I write it simplier? I mean, the name of the function shouldn't repeat.
removeIcons(document.querySelectorAll(".film-icon,.music-icon,.book-icon,..."))if(typeof x==='string') x = document.querySelectorAll(x);. That way you can call it with a string orNodeList-icon, you can have a more concise selector for all icons:'[class$="-icon"]'