It was supposed to be the CSS that controls the width and background color of the div in the HTML, but the JavaScript was used below to recall the div box and overwrite the original CSS property content.
Demand target: A 100-pixel pink background div box turns into a 300-pixel orange-colored div box
The code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">div{Background:pink; <!--background color: pink--width:100px; <!--width: 100 pixels--height:100px; <!--height: 100 pixels--}</style><!--JavaScript code can only be written in the tag body of the script below--><script>//Way One: //find the label with the ID div and continue looking for the style property //document.getElementById (' txt '). style.width= ' 300px '; //document.getElementById (' txt '). style.height= ' 300px '; //document.getElementById (' txt '). style.background= ' Orange '; //Way Two: //find the element with the ID txt first, put it in a variable, this process can be understood as the right side of the result is assigned to the left vart = document.getElementById (' txt '); //T is the variable name, which represents the location of the HTML box //sets the width of the box's style to 300 pixelsT.style.width= ' 300px '; //sets the height of the box's style to 300 pixelst.style.height= ' 300px '; //set the background color in the box's style to orangeT.style.background= ' Orange ';</script>
After running the following:
JavaScript first to talk about the JS operation CSS