HTML DOM tagName 属性
htmldomweb developmentfront end technology更新于 2025/12/27 21:00:17
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>
输出

点击"点击我以显示我的标签名称"按钮,显示红色按钮的标签名称。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

