반응형
속성 API
* 속성 : HTML 만으론 부족한 부가적인 정보
* 속성을 제어하는 API
<a id = "target" href="http://bravesuccess.tistory.com/">내 블로그</a>
<script>
var t = document.getElementById('target');
//http://bravesuccess.tistory.com/
document.write('<br/>'+t.getAttribute('href'));
// title 속성의 값을 설정한다.
t.setAttribute('title', 'bravesuccess');
// 존재하면 true, title 속성의 존재여부를 확인한다.
document.write('<br/>'+t.hasAttribute('title'));
// title 속성을 제거한다.
t.removeAttribute('title');
// false, title 속성의 존재여부를 확인한다.
document.write('<br/>'+t.hasAttribute('title'));
</script>* Element.getAttribute(name) : 속성 값 반환
* Element.setAttribute(name, value) : 속성의 값을 설정
* Element.hasAttribute(name); : 속성의 존재 여부 확인
* Element.removeAttribute(name); : 속성을 제거.
- 결과
반응형
'WEB > JavaScript' 카테고리의 다른 글
| Node 객체 (0) | 2016.10.15 |
|---|---|
| 속성과 프로퍼티 (0) | 2016.10.15 |
| Element 객체 : 조회 API (0) | 2016.10.15 |
| Element 객체 : 식별자 API (0) | 2016.10.15 |
| Element 객체 정의 (0) | 2016.10.15 |