面试题答案
一键面试<!DOCTYPE html>
<html>
<head>
<meta charset="UTF - 8">
<title>添加和移除class</title>
</head>
<body>
<div id="targetElement">这是目标元素</div>
<script>
// 添加class
const targetElement = document.getElementById('targetElement');
targetElement.classList.add('new - class');
// 移除class
setTimeout(() => {
targetElement.classList.remove('new - class');
}, 3000);
</script>
</body>
</html>