html attribute 와 DOM property 비교
1:1
HTML 태그 속성 <------> DOM 노드 속성
attribute property
js: .setAttribute(속성, 값) .속성명 = 값
값은 문자열만 가능 값은 객체 타입도 가능(string, object, array...)
class 속성: element.setAttribute("class", 클래스명) element.className = '클래스명'
checked 속성: element.setAttribute("checked", "checked") element.checked = true
jquery: $(선택자).attr(속성, string) $(선택자).prop(속성,any type)
표준속성이면 둘 다 적용됨
커스텀속성이면 다른쪽에 적용 안 됨
<a href="#" custom="custom" target="_blank">등록</a>
<script>
var a = document.querySelector("a");
console.log( a.getAttribute("custom") ); //커스텀 속성
console.log( a.getAttribute("target") ); //표준 속성
console.log( a.custom ); //커스텀 속성
console.log( a.target ); //표준 속성
a.title = "title"; // dom 속성에 추가됨 표준속성은 html 속성에도 추가됨
a.domcust = "domcust" // dom 속성에 추가됨 커스텀속성은 html 속성에는 추가안됨
a.setAttribute("title", "타이틀");
a.setAttribute("htmlcust", "htmlcust");
</script>