속성 API
속성을 제어하는 API
<a id="target" href="http://opentutorials.org">opentutorials</a>
<script>
let t = document.getElementById('target');
console.log(t.getAttribute('href')); // http://opentutorials.org
t.setAttribute('title', 'opentutorials.org'); // title 속성의 값을 설정한다.
console.log(t.hasAttribute('title')); // true, title 속성의 존재여부를 확인한다.
t.removeAttribute('title'); // title 속성을 제거한다.
console.log(t.hasAttribute('title')); // false, title 속성의 존재여부를 확인한다.
</script>속성과 프로퍼티
<p id="target">
Hello world
</p>
<script>
let target = document.getElementById('target');
// attribute 방식
target.setAttribute('class', 'important');
// property 방식
target.className = 'important';
</script>attribute 방식
property 방식
Last updated