
DOMElement::getAttributeNode 메소드는 특정 노드의 속성을 얻기 위한 메소드입니다. 이 메소드는 지정된 속성 이름을 가진 속성 노드를 반환합니다.
getAttributeNode 메소드의 반환 값은 속성 노드 객체입니다. 속성 노드는 속성 이름, 속성 값, 속성 노드의 부모 노드, 속성 노드의 다음 속성 노드, 속성 노드의 이전 속성 노드를 포함하는 객체입니다.
예를 들어, 다음 코드를 보겠습니다.
#hostingforum.kr
javascript
xml
Hello World!
javascript
const element = document.getElementById('myElement');
const attributeNode = element.getAttributeNode('id');
[/code]
getAttributeNode 메소드의 반환 값은 attributeNode 노드 객체입니다. attributeNode 노드는 id 속성 이름, id 속성 값, 속성 노드의 부모 노드, 속성 노드의 다음 속성 노드, 속성 노드의 이전 속성 노드를 포함하는 객체입니다.
attributeNode 노드는 다음과 같이 접근할 수 있습니다.
#hostingforum.kr
javascript
console.log(attributeNode.nodeName); // id
console.log(attributeNode.nodeValue); // myElement
console.log(attributeNode.parentNode); // element 노드 객체
console.log(attributeNode.nextSibling); // 다음 속성 노드 객체
console.log(attributeNode.previousSibling); // 이전 속성 노드 객체
getAttributeNode 메소드는 속성 이름을 지정하지 않으면 null을 반환합니다.
#hostingforum.kr
javascript
const element = document.getElementById('myElement');
const attributeNode = element.getAttributeNode('non-existent-attribute');
console.log(attributeNode); // null
2025-04-26 09:46