JavaScript / Object / Element.removeAttribute() / 요소의 속성을 제거하는 메서드
.removeAttribute()
.removeAttribute()는 요소의 속성을 제거하는 메서드입니다.
문법
element.removeAttribute( attributename )
예를 들어
document.getElementsByTagName( 'h1' )[0].removeAttribute( 'class' );
는 문서의 첫번째 h1 요소의 class 속성을 제거합니다.
예제
첫번째 h1 요소의 class 속성을 제거해서 글자색이 검정색이 됩니다.
<!doctype html> <html lang="ko"> <head> <meta charset="utf-8"> <title>JavaScript</title> <style> body { font-family: Consolas, monospace; } .abc { color: red; } </style> </head> <body> <h1 class="abc">Lorem Ipsum Dolor</h1> <h1 class="abc">Lorem Ipsum Dolor</h1> <script> document.getElementsByTagName( 'h1' )[0].removeAttribute( 'class' ); </script> </body> </html>