I am wondering why sometimes I can change the webpage background color and sometimes I can’t. For example, in some sites I just type in document.body.bgColor = “red” in the chrome console, and the background color changed temporarily. However, in the other sites like StackOverFlow, this doesn’t work. Since my browser has already loaded the page, I should be able to change how to displays it locally. Why not? Thank you
I am wondering why sometimes I can change the webpage background color and sometimes
Share
In Chrome you can use the DOM inspector to look at the computed style of the body and also the inheritance / overriding of CSS rules that result in this computed style.
If you set
document.body.style.backgroundColor(not thebgColorproperty) you’ll see that you can actually change the background color here. It all depends on whether there is another rule somewhere else with higher specificity or not. The DOM inspector will tell you whether that’s the case.