카테고리 없음

attribute(특성) vs property(속성)

allblack 2021. 9. 6. 09:47
반응형

사전적정의

  • attribute 는 html 문서에서 elements 에 추가적인 정보를 넣을 때 사용되는 요소입니다.
  • property는 html DOM 안에서 attribute 를 가리키는(혹은 대신하는) 표현입니다.

 

ex>

<div class="test">

class 라는 특성이 attribute이고

className(클래스명)은 property입니다!

 

..? 뭔 차이인가?

 

한줄요약

  • attribute는 정적인 값
  • property는 동적인 값

 

attributes는 html document/file안에 존재하는 값(파일)

property는 html dom tree안에 존재하는 값이기 때문입니다!(로컬)

 

 

이해하기 쉽게 예시를 들어보죠!

<input value="test" type="text"/>

이상태에서 각각의 값

  • attributes: "test"
  • property : "test"

지금은 이렇게 같은 값을 가르키고있지만 input에 test123을 입력하면

 

  • attributes: "test"
  • property : "test123"

으로 변경됩니다

반응형