Add class to an element

后端 未结 5 1605
遥遥无期
遥遥无期 2021-02-04 11:33

I try to write these code to make grid view through CSS:( jsbin )

   var tables = document.getElementsByClassName(\'tableData\');
    var rows = tables[0].getEle         


        
5条回答
  •  攒了一身酷
    2021-02-04 12:04

    Two years later (2012/06), there is a new and shiny approach - element.classList with methods add(), remove(), toggle(), contains().

    rows[i].classList.add("alt");
    

    Supported by

    • Chrome 8+
    • Firefox 3.6+
    • Internet Explorer 10+
    • Opera 11.50+
    • Safari 5.1+

提交回复
热议问题