• 회원가입
  • 로그인
  • 구글아이디로 로그인

[DOM_Element] JS - removeAttribute() 메서드 - 요소의 지정 속성 제거 (= removeAttribute메서드 = 리무브어트리뷰트메서드) ※ 속성제거

목차

  1. removeAttribute() 예제 - 속성 제거
  2. removeAttribute() 정의
  3. removeAttribute() 구문
  4. removeAttribute() 예제 - 여러 요소의 특정 속성 일괄 제거
  5. removeAttribute() 예제 - cf. value="";

 

removeAttribute() 예제 - 속성 제거

 

<style>

.hz {color: red;}

</style>


<h1 class="hz">홈짱닷컴 Homzzang.com</h1>


<button onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  document.getElementsByTagName("H1")[0].removeAttribute("class"); 

}

</script>

 

결과보기

 

removeAttribute() 정의

 

해당 요소에서 지정 속성 제거. (※ 반환값은 없음.)

 


 

1. cf. 아래 두 메서드는 결과는 동일하나, 동작 방식이 다름.

  • removeAttribute() - 속성제거. / 반환값 없음
  • removeAttributeNode() - Attr 객체 제거. / 제거된 객체 반환.

 

2. cf.

 

3. HTML attribute (속성) 강의
https://homzzang.com/b/html?sca=attribute

 

4.

  • DOM Level 1 (1998)
  • 모든 브라우저 지원

  

5. MDN removeAttribute() 예제 더 보기
https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute

 

 

removeAttribute() 구문

 

element.removeAttribute(name)

 


[매개변수]

 

name

필수. 제거할 속성명

 


[반환값]

 

없음.

 

 

removeAttribute() 예제 - 여러 요소의 특정 속성 일괄 제거

 

<div class="hz">

    <a href='#' rel="nofollow noreferrer noopener">링크A</a>

    <a href='#' rel="nofollow noreferrer noopener">링크B</a>

</div>


<script>

for (i of document.querySelectorAll(".hz a")) i.removeAttribute("rel");

</script>

 

결과보기


PS. 참고


rel="nofollow noreferrer noopener" 경우, 보안 관련 코드라 비삭제 권장. (<a> 태그 목차 22~23 참고)

 

 

removeAttribute() 예제 - cf. value="";

 

<input id="hz" name="hz" type="text" value="https://homzzang.com">

 


PS. value 속성의 속성값 제거 방식 차이

 

  • hz.removeAttribute("value"); --> value 속성 조차 제거
  • hz.value=""; --> value 속성의 속성값만 제거

 



분류 제목
DOM_Event_Object JS - StorageEvent 객체 - 윈도우창 저장영역 변경 (= 스토리지이벤트객체= 스토리지이벤트종류)
DOM_Event_Object JS - TouchEvent 객체 - 터치이벤트객체 (= 터치이벤트종류)
DOM_Event_Object JS - TransitionEvent 객체 - CSS 전환 실행 (= 트랜지션이벤트객체 = 트랜지션이벤트종류…
DOM_Event_Object JS - UiEvent 객체 - 유저인터페이스변환 (= 유아이이벤트객체 = 유저인터페이스이벤트종류 = 사용자…
DOM_Event_Object JS - WheelEvent 객체 - 마우스휠움직임 (= 휠이벤트객체)
API_Geolocation JS - coordinates -
API_Geolocation JS - position -
API_Geolocation JS - positionError -
API_Geolocation JS - positionOptions -
API_Geolocation JS - clearWatch() 메서드 -
API_Geolocation JS - getCurrentPosition() 메서드 -
API_Geolocation JS - watchPosition() 메서드 -
Window_History JS - history.length 속성 - history개수 (= 방문이력개수 = 방문주소개수 = 히스토리…
Window_History JS - history.back() 메서드 ★ - 이전페이지 가기
Window_History JS - history.forward() 메서드 - 다음페이지 가기
Window_History JS - history.go() 메서드 ★ - 특정페이지로 이동 (= history.go메서드 = 히스토리고…
DOM_HTMLCollection JS - item() 메서드 ★ - 지정 인덱스의 요소 반환 (= 특정 순번째 요소 반환)
DOM_HTMLCollection JS - length 속성 ★ - 요소개수 반환 (※ for반복문에 활용)
DOM_HTMLCollection JS - namedItem() 메서드 - 지정 id 또는 name 갖는 요소 반환
Window_Location JS - hash 속성 - URL앵커부분(= 샵부분 = 해시속성) 설정/반환
40/67
목록
찾아주셔서 감사합니다. Since 2012