js Three Ways to Change the Style of css
- 2021-07-01 06:22:58
- OfStack
Common code:
<
div id="div"
>
this is a div
<
/div
>
var div=document.getElementById('div');
Type 1: cssText
div.style.cssText='width:250px;height:250px;border:1px red solid;';
Type 2: Use setProperty ()
div.style.setProperty('width','250px');
div.style.setProperty('height','250px');
div.style.setProperty('border','1px red solid');
Type 3: Use the style attribute corresponding to the css attribute
div.style.width = "250px";
div.style.height = "250px";
div.style.border = "1px solid red";