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";
精彩评论