Home > Web Front-end > CSS Tutorial > What does classlist in css mean?

What does classlist in css mean?

醉折花枝作酒筹
Release: 2023-01-07 11:43:17
Original
7053 people have browsed it

The classList attribute returns the class name of the element as a DOMTokenList object. This attribute is used to add, remove and switch CSS classes in the element. The classList attribute is read-only, but you can modify it using the add() and remove() methods.

What does classlist in css mean?

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

The classList property returns the class name of the element as a DOMTokenList object.

This property is used to add, remove and switch CSS classes in elements.

The classList property is read-only, but you can modify it using the add() and remove() methods.

Syntax

element.classList
Copy after login

What does classlist in css mean?

Method

What does classlist in css mean?

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>document</title>
<style>
.mystyle {
    width: 500px;
    height: 50px;
    padding: 15px;
    border: 1px solid black;
}
.anotherClass {
    background-color: coral;
    color: white;
}
.thirdClass {
    text-transform: uppercase;
    text-align: center;
    font-size: 25px;
}
</style>
</head>
<body>

<p>点击按钮为 DIV 元素添加多个类。</p>
<button onclick="myFunction()">点我</button>
<p><strong>注意:</strong> Internet Explorer 9 及更早 IE 版本浏览器不支持 classList 属性。</p>
<div id="myDIV">
我是一个 DIV 元素。
</div>
<script>
function myFunction() {
    document.getElementById("myDIV").classList.add("mystyle", "anotherClass", "thirdClass");
}
</script>

</body>
</html>
Copy after login

Effect:

What does classlist in css mean?

Recommended learning: css video tutorial

The above is the detailed content of What does classlist in css mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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