开发者

Adding CSS to to when creating a tablecell in javascript

I'm creating a tablec开发者_运维技巧ell in javascript and trying to add a css style that I created but for some reason its not working. I know im close but not sure exactly whats wrong here is my code below: The bold line is where im having the trouble

    var cellLeft = row.insertCell(0);
    var el = document.createElement('input');
    el.type = 'text';
    el.id = 'textField1';
    **cellLeft.setAttribute("class", "MainTableHeader");**
    cellLeft.appendChild(el);


To add the class to your element you should use the className property like so:

cellLeft.className += "MainTableHeader";


cellLeft.className += "MainTableHeader";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜