Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:15:47
Original
893 people have browsed it

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>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template