Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- RxKotlin
- android13
- google play
- GCP
- php
- Koin
- SwiftUI Tutorial
- Android 13
- 테스트 자동화
- MotionLayout
- rx
- SWIFTUI
- MediaSession
- node.js
- mysql
- Kotlin
- Observable
- node
- databinding
- MediaPlayer
- PagingLib
- Reactive
- list
- Android
- 동영상
- Animation
- junit
- 인앱결제
- mvvm
- paging
Archives
- Today
- Total
봄날은 갔다. 이제 그 정신으로 공부하자
[JavaScript] id로 요소의 부모 또는 자식 요소 찾기 본문
// id로 Element를 가져온다.
var articles = document.getElementById(“articles”);
// element의 자식 노드가 있는지 확인한다.
if(articles.hasChildNodes()) {
var children = articles.childNodes;
// 자식 노드 갯수만큼 반복한다.
for(var i=0; i<children.length; i++){
// 자식 노드에서 필요한 정보를 가져온다.
console.log('nodeName: ' + children[i].nodeName);
console.log('name: ' + children[i].getAttribute('name'));
console.log('class: ' + children[i].className);
console.log('article-idx: ' + children[i].getAttribute('article-idx'));
}
}
// element의 부모 노드를 가져온다.
var parent = demodiv.parentNode;
// 보무 노드가 있는지 확인
if(parent != null){
// 부모 노드에서 필요한 정보를 가져온다.
console.log('nodeName: ' + parent.nodeName);
console.log('name: ' + parent.getAttribute('name'));
console.log('class: ' + parent.className);
}