jQuery 사전

jQuery API 레퍼런스를 번역한 것입니다.

jQuery 사전 jQuery API 레퍼런스를 번역한 것입니다.

removeAttr

.removeAttr(attributeName)

요약

선택된 엘리먼트 그룹 전체 엘리먼트의 속성을 제거한다.

문법

 .removeAttr(attributeName)

인자

인자명 데이터형 필수/옵션 설명
attrubiteName String 필수 제거하려는 속성의 이름

버전

1.0

반환값

jQuery wrapper Object

설명

removeAttr 메서드는 javascript의 removeAttribute 함수를 이용한다. 하지만 .removeAttr() 메서드를 사용하면 jQuery 객체에서 직접 호출할 수 있다는 이점이 있다. 그리고 이는 브라우저마다 어트리뷰트의 이름을 다르게 붙이는 이유를 설명해준다. 

참고 : 만약 onclick과 같은 inline 이벤트를 삭제하려고 할 때는 .removeAttr() 보다는 .prop()을 이용하는 것을 권한다. ie6,7,8에서 예상했던 것과는 다르게 작동할 수 있기 때문이다. 아래는 .prop를 이용한 예다.

$element.prop("onclick", null);
console.log("onclick property: ", $element[0].onclick);

예제

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <button>Enable</button>
<input type="text" disabled="disabled" value="can't edit this" />
<script>
$("button").click(function () {
  $(this).next().removeAttr("disabled")
  .focus()
  .val("editable now");
});
</script>

</body>
</html>

참고

댓글

댓글 본문
버전 관리
egoing
현재 버전
선택 버전
graphittie 자세히 보기