HTML DOM의 deleteTHead() 메서드는 HTML 문서 내 테이블에서 <thead> 요소를 제거하는 기능을 합니다. 이 메서드는 테이블 객체(Table Object)에 포함되어 있으며, 매개변수 없이 호출하기만 하면 해당 테이블의 머리글 영역이 즉시 삭제됩니다.
문법(Syntax)
기본 사용 문법은 다음과 같습니다.
object.deleteTHead()
반환값은 없으며, 대상 테이블에 <thead> 요소가 존재하지 않으면 아무 작업도 수행하지 않습니다.
예제(Example)
아래 예제는 HTML DOM 테이블 deleteTHead() 메서드가 실제로 어떻게 동작하는지 보여줍니다. 버튼을 클릭하면 테이블의 머리글이 화면에서 사라집니다.
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
background: lightblue;
height: 100vh;
text-align: center;
}
table {
margin: 2rem auto;
}
caption {
color: #db133a;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
.show {
font-size: 1.2rem;
}
</style>
<body>
<h1>DOM Table deleteTHead() Method Demo</h1>
<table border="2">
<thead>
<tr>
<th>Name</th>
<th>Roll No.</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>071717</td>
</tr>
<tr>
<td>Jane</td>
<td>031717</td>
</tr>
</tbody>
</table>
<button onclick="remove()" class="btn">Remove Header</button>
<script>
function remove() {
document.querySelector('table').deleteTHead();
}
</script>
</body>
</html>
실행 결과(Output)

초기 화면에는 'Name'과 'Roll No.'라는 두 개의 열 제목을 가진 머리글이 표시됩니다. 여기서 "Remove Header" 버튼을 클릭해 보세요.

버튼을 클릭하면 deleteTHead() 메서드가 실행되어 테이블에서 <thead> 요소가 완전히 제거되고, 데이터 행(<tbody>)만 남게 됩니다.
참고: 관련 테이블 메서드
deleteTHead()와 함께 알아두면 유용한 테이블 관련 DOM 메서드는 다음과 같습니다.
- createTHead(): 테이블에 새로운 <thead> 요소를 생성하거나 기존 요소를 반환합니다.
- createTFoot(): 테이블에 새로운 <tfoot> 요소를 생성하거나 기존 요소를 반환합니다.
- deleteTFoot(): 테이블에서 <tfoot> 요소를 삭제합니다.
- insertRow(): 테이블에 새로운 행(<tr>)을 삽입합니다.
이 메서드들은 모든 주요 브라우저(Chrome, Firefox, Safari, Edge, Opera)에서 지원되므로 호환성 걱정 없이 사용할 수 있습니다.