Body Toggle

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");">

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!

原文来自:www.php.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容