开发者

Javascript: Change bgColor of a table cell

I want to change the color of one specific cell in my table: Why does the following not work?

document.getElementById('myTable').rows[i].cells[j].bgColor="#mybgColor";开发者_运维百科

where i and j are some integers certainly within the range of the rows and cells. I don't need any fancy JQuery or so, just this simple command.


CSS styles will override the bgColor attribute, which is deprecated. Use .style.backgroundColor instead of .bgColor:

document.getElementById('myTable').rows[i].cells[j].style.backgroundColor = "#003366";


If you just happen to really like bgColor, or you need to change an attribute; use this:

document.getElementById('myTable').rows[i].cells[j].setAttribute('bgColor', 'red');

setAttribute


This should work

object.style.backgroundColor="#00FF00"


...cells[0].style.bgColor = '#002200';
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜