Removing elements by class name?

后端 未结 16 1748
猫巷女王i
猫巷女王i 2020-11-27 12:06

I have the below code to find elements with their class name:

// Get the element by their class name
var cur_columns = document.getElementsByClassName(\'colu         


        
16条回答
  •  甜味超标
    2020-11-27 12:51

    I prefer using forEach over for/while looping. In order to use it's necessary to convert HTMLCollection to Array first:

    Array.from(document.getElementsByClassName("post-text"))
        .forEach(element => element.remove());
    

    Pay attention, it's not necessary the most efficient way. Just much more elegant for me.

提交回复
热议问题