How to replace css style in js
This article mainly introduces how to replace the css style in js, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
1. Use obj.className to modify the class name of the style sheet.
Function changeStyle1 () {var obj = document.getElementById ("btnB"); obj.style.backgroundColor= "black";}
2. Use obj.style.cssText to modify embedded css.
Function changeStyle2 () {var obj = document.getElementById ("btnB"); obj.style.cssText = "background-color:black; display:block; color:White;}
Use obj.className to modify the class name of the stylesheet.
Function changeStyle3 () {var obj = document.getElementById ("btnB"); / / obj.className = "style2"; obj.setAttribute ("class", "style2");}
4. Use the css file that changes the outreach to change the css of the element.
Function changeStyle4 () {var obj = document.getElementById ("css"); obj.setAttribute ("href", "css2.css");} Thank you for reading this article carefully. I hope the article "how to replace css style in js" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!