Home  >  Article  >  Web Front-end  >  JavaScript changes the style of HTML elements, changes CSS and element attributes_javascript skills

JavaScript changes the style of HTML elements, changes CSS and element attributes_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:15:47870browse

Change HTML style
To change the style of HTML elements, please use this syntax:

Copy the code The code is as follows:

document.getElementById(id).style.property=new style

Hello World!


<script> <br>document.getElementById("p2").style.color="blue"; <br></script>

JS changes element attributes;
Copy code The code is as follows:

<script> <br>var div = document.getElementByIdx_x('d1'); <br> div.setAttribute("class", "abc"); <br></script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn