jQuery / Method / .removeAttr() - 선택한 요소의 특정 속성을 제거하는 메서드
목차
.removeAttr()
.removeAttr()은 선택한 요소의 특정 속성을 제거한다.
문법
- attributeName 속성을 제거한다.
.removeAttr( attributeName )
- 예를 들어 아래는 h1 요소에서 title 속성을 제거한다.
$( 'h1' ).removeAttr( 'title' );
예제
- input 요소의 placeholder 속성을 제거한다.
<!doctype html> <html lang="ko"> <head> <meta charset="utf-8"> <title>jQuery</title> <style> input { font-size: 30px; } </style> <script src="//code.jquery.com/jquery-3.3.1.min.js"></script> <script> $( document ).ready( function() { $( 'input' ).removeAttr( 'placeholder' ); } ); </script> </head> <body> <input type="text" name="address" placeholder="Input Address"> </body> </html>
참고
- 속성 추가는 .attr()로 할 수 있다.
- 클래스(class)의 값(value) 삭제는 .removeClass()로 할 수 있다.
- 요소를 제거할 때는 .remove()를 사용한다.