HTML DOM tagname 속성은 HTML 문서에 있는 HTML 요소의 태그 이름을 반환합니다.
구문
다음은 구문입니다 -
element.tagName
HTML DOM tagName 속성의 예를 살펴보겠습니다-
예시
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background-color: #FBAB7E;
background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
text-align: center;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
</style>
</head>
<body>
<h1>HTML DOM tagName Property Demo</h1>
<button class="btn" onclick="display()">Click me to show my tag name</button>
<div class="show"></div>
<script>
function display() {
document.querySelector('.show').innerHTML = 'Tag name is: ' + document.querySelector('button').tagName;
}
</script>
</body>
</html> 출력

"내 태그 이름을 표시하려면 클릭하세요 ” 버튼을 눌러 빨간색 의 태그 이름을 표시합니다. 버튼.
