What is the usage of style in javascript

WBOY
Release: 2022-01-05 12:07:17
Original
3596 people have browsed it

In JavaScript, style is used to change the style of the set element. The style object represents a separate style declaration. The set style object can be accessed from the document or element to which the style is applied. The syntax is "element object.style.style. Attribute="style attribute value";".

What is the usage of style in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What is the usage of style in javascript

The Style object represents a separate style statement. A Style object can be accessed from the document or element to which the style is applied.

The syntax for using the Style object attribute:

document.getElementById("id").style.property="值"
Copy after login

The example is as follows:

<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <p id="xuebi">这一段看不见</p>
<p>这是能看见的段落</p>
<script type="text/javascript">
document.getElementById("xuebi").style.display="none";
</script>
</body>
</html>
Copy after login

Output result:

What is the usage of style in javascript

[Related Recommended: javascript learning tutorial

The above is the detailed content of What is the usage of style in javascript. For more information, please follow other related articles on the PHP Chinese website!

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