开发者

Adding CSS to to when creating a tablecell in javascript

开发者 https://www.devze.com 2023-04-03 11:53 出处:网络
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 cod

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

精彩评论

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