jQuery / Reference / .removeAttr()

개요

  • .removeAttr()은 선택한 요소의 특정 속성을 제거합니다.

문법

.removeAttr( attributeName )
  • 예를 들어 아래는 h1 요소에서 title 속성을 제거합니다.
$( 'h1' ).removeAttr( 'title' );

예제

  • 버튼을 클릭하면 input 요소의 placeholder 속성을 제거합니다.
<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>jQuery</title>
    <style>
      * {
        font-size: 40px;
      }
    </style>
    <script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
    <script>
      $( document ).ready( function() {
        $( 'button' ).click( function() {
          $( 'input' ).removeAttr( 'placeholder' );
        } );
      } );
    </script>
  </head>
  <body>
    <button>Click</button>
    <input type="text" name="address" placeholder="Input Address">
  </body>
</html>

참고

  • 속성 추가는 .attr()로 할 수 있습니다.
같은 카테고리 다른 글
jQuery / Reference / .each()

jQuery / Reference / .each()

jQuery의 .each() 함수는 주로 배열, 객체, 또는 jQuery 선택자로 선택된 요소 집합에 대해 반복 작업을 수행하기 위해 사용됩니다. JavaScript의 for 또는 forEach 루프와 유사하지만, jQuery의 특성과 통합된 방식으로 작동합니다.

jQuery / Reference / :contains()

jQuery / Reference / :contains()

:contains()는 특정 문자열을 포함한 요소를 선택하는 선택자입니다. 문자열 포함 여부를 따질 때 대소문자를 구분한다는 점에 주의합니다.

jQuery / Reference / :button

jQuery / Reference / :button

:button은 type이 button인 요소를 선택하는 선택자입니다.

jQuery / Reference / .width()

jQuery / Reference / .width()

.width()는 선택한 요소의 가로 크기를 반환하거나, 가로 크기를 변경합니다.

jQuery / Reference / .val()

jQuery / Reference / .val()

개요 .val()은 양식(form)의 값을 가져오거나 값을 설정합니다. 문법 1 .val() 선택한 양식의 값을 가져옵니다. 예를 들어 다음은 아이디가 jbInput인 input 요소의 값을 변수 jb에 저장합니다. var jb = $( 'input#jbInput' ).val(); 문법 2 .val( value ) 선택한 양식의 값을 설정합니다. 예를 들어 다음은 아이디가 jbInput인 input 요소의 값을 ABCDE로 정합니다. $( 'input#jbInput' ).val( 'ABCDE' ); 예제 1 양식에 텍스트를 입력하고 버튼을 클릭하면, ...