JavaScript를 사용하여 요소에서 클래스 이름을 제거하는 코드는 다음과 같습니다. -
예시
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
.newStyle {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
width: 100%;
padding: 25px;
background-color: rgb(147, 80, 255);
color: white;
font-size: 25px;
box-sizing: border-box;
text-align: center;
}
</style>
</head>
<body>
<h1>Remove className with JavaScript Example</h1>
<button class="btn">Remove Class</button>
<h2>Click the above button to remove className from below div</h2>
<div class="newStyle" id="sampleDiv">
This is a DIV element.
</div>
<script>
document.querySelector(".btn").addEventListener("click", addClassName);
function addClassName() {
var element = document.getElementById("sampleDiv");
element.classList.remove("newStyle");
}
</script>
</body>
</html> 출력
위의 코드는 다음과 같은 출력을 생성합니다 -

"수업 제거" 버튼 클릭 시 -
