HTML DOM removeAttributeNode() 메서드는 HTML 문서의 지정된 요소에서 해당 매개변수에 지정된 속성을 제거하고 제거된 속성을 Attr 노드 객체로 반환합니다.
구문
다음은 구문입니다 -
node.removeAttributeNode(attributeNode);
예시
removeAttributeNode() 메소드의 예를 보자 -
<!DOCTYPE html>
<html>
<head>
<style>
html{
height:100%;
}
body{
text-align:center;
color:#fff;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
height:100%;
}
.btn{
background:#0197F6;
border:none;
height:2rem;
border-radius:2px;
width:35%;
margin:2rem auto;
display:block;
color:#fff;
outline:none;
cursor:pointer;
}
</style>
</head>
<body>
<h1>DOM removeAttributeNode() method Demo</h1>
<p style="color:#db133a;font-size:1.2rem;">Hi! I'm a para element in HTML with some random text</p>
<button onclick="remove()" class="btn">Remove Attribute</button>
<script>
function remove() {
var p=document.querySelector("p");
var pAtt=p.getAttributeNode("style");
p.removeAttributeNode(pAtt);
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

"속성 제거를 클릭합니다. ” 버튼을 눌러
요소에서 스타일 속성을 제거합니다.
