Shared code:
<div id="div">
This is a div
</div>
var div=document.getElementById('div');
The first type: use cssText
div.style.cssText='width:250px;height:250px;border:1px red solid;';
The second type: use setProperty()
div.style.setProperty('width','250px');
div.style.setProperty('height','250px');
div.style.setProperty('border','1px red solid');
The third type: use the style attribute corresponding to the css attribute
div.style.width = "250px";
div.style.height = "250px";
div.style.border = "1px solid red";
The above is the three recommended ways to change the css style of js brought to you. I hope everyone will support Wulin.com more~