Home > Web Front-end > CSS Tutorial > Body Toggle

Body Toggle

尊渡假赌尊渡假赌尊渡假赌
Release: 2025-03-22 10:30:31
Original
469 people have browsed it

Body Toggle

I appreciate the clarity of this trick that Mikael Ainalem posted over on Reddit:

It’s a one-liner that toggles the class on the so you can mock up different states and toggle between them on click.

<body onclick="this.classList.toggle("active");">
Copy after login

Could be on any element as well!

This can be a big thing. See “The Power of Changing Classes” as a case in point. Even if you aren’t much of a JavaScript person, classList is perhaps the one API you should know.

The above is the detailed content of Body Toggle. For more information, please follow other related articles on the PHP Chinese website!

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