Add class to an element

后端 未结 5 1616
遥遥无期
遥遥无期 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 11:57

    This should work even when the attribute isn't already present:

    rows[i].setAttribute("class", "alt");
    

    http://www.w3schools.com/Dom/met_element_setattribute.asp

提交回复
热议问题