
`getAttributeNodeNS` 메소드는 NS 속성을 가지는 특정 엘리먼트의 속성을 가져올 때 사용됩니다. 이 메소드는 엘리먼트의 속성을 가져올 때 사용할 수 있습니다. 예를 들어, 다음 HTML 코드가 있습니다.
#hostingforum.kr
html
Hello World!
위의 HTML 코드에서 `getAttributeNodeNS` 메소드를 사용하여 속성을 가져올 수 있습니다.
#hostingforum.kr
javascript
const span = document.getElementById('test');
const attr = span.getAttributeNodeNS('http://example.com', 'custom:attr');
console.log(attr.value); // value
`getAttributeNodeNS` 메소드를 사용하여 속성을 가져올 때, `null`이 반환되는 경우는 다음과 같습니다.
- 엘리먼트가 존재하지 않는 경우
- 속성이 존재하지 않는 경우
- 속성이 NS 속성이 아닌 경우
- 속성이 존재하지 않는 NS 속성이 있는 경우
예를 들어, 다음 HTML 코드가 있습니다.
#hostingforum.kr
html
Hello World!
위의 HTML 코드에서 `getAttributeNodeNS` 메소드를 사용하여 속성을 가져올 수 없습니다.
#hostingforum.kr
javascript
const span = document.getElementById('test');
const attr = span.getAttributeNodeNS('http://example.com', 'custom:attr');
console.log(attr); // null
이러한 경우, `getAttributeNodeNS` 메소드는 `null`을 반환합니다.
2025-04-12 02:13