document.getelementbyid("aa").classname="bbbb";"."/> document.getelementbyid("aa").classname="bbbb";".">

Home  >  Article  >  Web Front-end  >  How to add class in javascript

How to add class in javascript

藏色散人
藏色散人Original
2021-09-10 15:11:0024605browse

How to add class in javascript: 1. Create a p element; 2. Use "<script>document.getelementbyid("aa").classname="bbbb";</script>" Just add a class to the element.

How to add class in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to add a class in javascript?

First we create a p element and write hello in it:

How to add class in javascript

The display on the browser interface is as follows:

How to add class in javascript

Next, you can use js to add a class to the element:

How to add class in javascript

After adding it, let us see the result in the browser console:

How to add class in javascript

Isn’t it very simple? After adding it, you can use class to It is very convenient to add some styles dynamically. After removing them, the styles will be gone.

How to add class in javascript

Recommended study: "javascript basic tutorial"

The above is the detailed content of How to add class in javascript. For more information, please follow other related articles on the PHP Chinese website!

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
Previous article:What does es6 arrow mean?Next article:What does es6 arrow mean?