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 |
Tags
- Sass
- JS
- close together
- Prototype
- flex-grow
- node
- flex-shrink
- Node.js
- select by attribute
- img 확대
- css variables
- improve-iq-by-up-to-10%!
- css grid
- just-one-small-sip
- flexbox
- 정규표현식
- 디자인패턴
- 무료 백엔드 배포
- Engoo
- regExp
- ajax
- express-handlebars
- css 오버레이
- flex-basis
- Object.create
- shit-christmas
- es6
- module wrapper function
- Express
- css
Archives
- Today
- Total
traversing dom 본문
let val;
const list = document.querySelector("ul.collection");
const listItem = document.querySelector("li.collection-item:first-child");
val = listItem;
val = list;
// Get child nodes
val = list.childNodes; // count line breaker as a text node.
val = list.childNodes[0];
val = list.childNodes[0].nodeName;
val = list.childNodes[1].nodeType;
// nodetypes
// 1 - Element
// 2 - Attribute
// 3 - Text node
// 8 - Comment
// 9 - Document itself
// 10 - Doctype
// get children element nodes
// val = list.children; // just elements. return HTMLCollection
val = list.children;
val = list.children[1];
list.children[1].textContent = "Hello";
// Children of children
list.children[3].children[0].id = "test-id";
val = list.children[3].children[0];
// First child
val = list.firstChild; // text node
val = list.firstElementChild; // element
// last child
val = list.lastChild; // text node
val = list.lastElementChild; // element
// Count child elements
val = list.childElementCount;
// Get parent node
val = listItem.parentNode;
val = listItem.parentElement;
val = listItem.parentElement.parentElement;
// Get next sibling
val = listItem.nextSibling;
val = listItem.nextElementSibling.nextElementSibling.previousElementSibling;
// Get Next
// val = listItem.previousSibling;
// val = listItem.previousElementSibling; // null
console.log(val);
'2021 프론트 엔드 로드맵 따라가기 > JS' 카테고리의 다른 글
Replace & Remove Elements (0) | 2021.05.31 |
---|---|
Creating Elements (0) | 2021.05.31 |
Multiple Selector (0) | 2021.05.30 |
single selector (0) | 2021.05.30 |
Document Object (0) | 2021.05.30 |
Comments