<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box{
width: 100px;
height: 100px;
background: red;
}
.show{
display: block;
}
.hide{
display: none;
}
</style>
</head>
<body>
<button id="btn">show/hide</button>
<div id="box" class="box show hide">111</div>
<script>
const box=document.getElementById('box')
const btn=document.getElementById('btn');
btn.onclick=function(){
const className=box.className
console.log(className);
console.log(typeof className)
if(className.includes('hide')){
box.className=''
box.classList.add('show');
box.classList.add('box')
}else{
box.className=''
box.classList.add('hide')
box.classList.add('box')
}
}
</script>
</body>
</html>