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
- close together
- img 확대
- flex-shrink
- regExp
- css
- express-handlebars
- node
- css variables
- Express
- 무료 백엔드 배포
- module wrapper function
- Sass
- Prototype
- select by attribute
- shit-christmas
- es6
- just-one-small-sip
- 정규표현식
- Engoo
- css grid
- Node.js
- improve-iq-by-up-to-10%!
- flex-basis
- Object.create
- flex-grow
- flexbox
- 디자인패턴
- ajax
- JS
- css 오버레이
Archives
- Today
- Total
Multiple Selector 본문
선택자에 따라 HTMLCollection과 NodeList 두 가지 리턴형식이 존재
// document.getElementsByClassName
// const items = document.getElementsByClassName("collection-item");
// console.log(items);
// console.log(items[0]);
// items[0].style.color = "red";
// items[3].textContent = "Hello";
// const listItems = document.querySelector("ul").getElementsByClassName("collection-item");
// console.log(listItems);
// document.getElementsByTagName
// let lis = document.getElementsByTagName("li");
// console.log(lis);
// console.log(lis[0]);
// lis[0].style.color = "red";
// lis[3].textContent = "Hello";
// // Converse HTML Collection into Array
// lis = Array.from(lis);
// lis.reverse();
// lis.forEach((li, index) => {
// console.log(li.className);
// li.textContent = `${index}: Hello`;
// });
// console.log(lis);
// document.querySelectorAll => return NodeList which allow to use forEach, etc..
const items = document.querySelectorAll("ul.collection li.collection-item");
items.forEach((item, index) => {
item.textContent = `${index}: Hello`;
});
const liOdd = document.querySelectorAll("li:nth-child(odd)");
const liEven = document.querySelectorAll("li:nth-child(even)");
liOdd.forEach((li, index) => {
li.style.background = "#ccc";
});
for(let i = 0; i < liEven.length; i++) {
liEven[i].style.background = "#f4f4f4";
}
console.log(items);
'2021 프론트 엔드 로드맵 따라가기 > JS' 카테고리의 다른 글
Creating Elements (0) | 2021.05.31 |
---|---|
traversing dom (0) | 2021.05.30 |
single selector (0) | 2021.05.30 |
Document Object (0) | 2021.05.30 |
Variable Scope (0) | 2021.05.30 |
Comments