๐localStorage๋?์๋ฒ์ ์ ์ฅํ ์ ๋๋ก ์ค์ํ์ง ์์ ์ ๋ณด๋ฅผ ์ ์ฅํ๊ธฐ ์ํด ์ฌ์ฉ์ค์ํ์ง ์์ ์ ๋ณด๋ ์ ๋ณด๊ฐ ๋ ๋ผ๊ฐ๋ ์๊ด์ ์์ง๋ง ์์ผ๋ฉด ํธ๋ฆฌํ ์ ๋ณดex) “์ค๋ ๊ทธ๋ง ๋ณด๊ธฐ” ๋ฒํผ ํด๋ฆญ ์ฌ๋ถDB๋ฅผ ์ฌ์ฉํ์ง ์๊ธฐ ๋๋ฌธ์ ์ฐ์ต์ฉ์ผ๋ก ๋ก์ปฌ์คํ ๋ฆฌ์ง์ ์ ์ฅ, ์ญ์ ํ๋ ์ฐ์ต ๐localStorage ๋ค์ํ ์ฌ์ฉ๋ฒ๋ก์ปฌ์คํ ๋ฆฌ์ง์ ๋ฐ์ดํฐ ์ถ๊ฐํ๊ธฐ or ์์ ํ๊ธฐ localStorage.setItem("์ํ๋ช ", "๋ฉ์๋ ์ ์ธ ") ๋ก์ปฌ์คํ ๋ฆฌ์ง์์ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐlocalStorage.getItem("์ํ๋ช ")// "๋ฉ์๋ ์ ์ธ " ๋ก์ปฌ์คํ ๋ฆฌ์ง์ ๋ฐ์ดํฐ ์ญ์ ํ๊ธฐlocalStorage.removeItem("์ํ๋ช ") ๐๋ก์ปฌ์คํ ๋ฆฌ์ง์ ๋ฌธ์ ์ 1. ์ ์ฅ ๋ฐ ๋ถ๋ฌ์ค๊ธฐ ์ ๋ฐ์ดํฐ๊ฐ ๋ฌธ์์ด๋ก๋ง ์ ์ฅ๋๋ค. 2. Arra..
๐์ด๋ฒคํธ ๋ฒ๋ธ๋ง์ด๋?๊ฑฐํ์ด ๊ณ์ํด์ ์ปค์ง๋ ๊ฒ์ฒ๋ผ ๋ด๋ถ์ ๋ฐ์ํ ์ด๋ฒคํธ๊ฐ ์ธ๋ถ๋ฌ ๋ป์ด๋๊ฐ๋ ํ์์ด๋ค. ์์๋ก ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด๊ฒ ๋ค.๋๋ณด๊ธฐ๋๋ณด๊ธฐ๋ชจ๋ฌ์ฐฝ ์ธํ [index.html] ๋ณธ๋ฌธ ๋ชจ๋ฌ์ด๊ธฐ ๋ก๊ทธ์ธํ๊ธฐ ๋ซ๊ธฐ [styles.css].modal { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: gray; opacity: 0.8; /* ์ถ๊ฐ */ display: none; padding-top: 100px;}.modal-content { width: 200px; height: 200px; background-color: white; padding: 20p..
๋ณ์ : ๋ธ๋ก ์ค์ฝํ ๋ฌธ์ ๋ค์์ ์ํํ์ธ์:1. blockScopeTest ํจ์ ๋ด๋ถ์ ๋ธ๋ก({})์ ์์ฑํ์ธ์.2. ๋ธ๋ก ๋ด๋ถ์ let ํค์๋๋ก ๋ณ์ w๋ฅผ ์ ์ธํ๊ณ ๊ฐ 1์ ํ ๋นํ์ธ์.3. ๊ฐ์ ๋ธ๋ก ๋ด๋ถ์ var ํค์๋๋ก ๋ณ์ u๋ฅผ ์ ์ธํ๊ณ ๊ฐ 2๋ฅผ ํ ๋นํ์ธ์.4. ๋ธ๋ก ์ธ๋ถ์์ w์ ์ ๊ทผํ์ฌ ์ฝ์์ ์ถ๋ ฅํ์ธ์. (ReferenceError๊ฐ ๋ฐ์ํด์ผ ํฉ๋๋ค.)5. ๋ธ๋ก ์ธ๋ถ์์ u์ ์ ๊ทผํ์ฌ ์ฝ์์ ์ถ๋ ฅํ์ธ์. (๊ฐ 2๊ฐ ์ถ๋ ฅ๋์ด์ผ ํฉ๋๋ค.) ๐๊ตฌํํ ์ฝ๋function blockScopeTest() { { let w = 1; var u = 2; } // ๋ธ๋ก ์ธ๋ถ์์ ๋ณ์ ์ ๊ทผ console.log(w); console.log(u);}๋ถ๋ช ๋ง๊ฒ ์์ฑํ ๋ฏ ํ๋ฐ ๊ณ์ ์ค๋ฅ๊ฐ ๋ฌ..
Promise fetch๋ Promise๋ฅผ return ํ๋ ํจ์์ด๋ค. ๐fetch๋? ์ธ๋ถ์์ ๋ฐ์ดํฐ(์ ๋ณด)๋ฅผ ๊ฐ์ ธ์ค๋ ํจ์ ๐Promise๊ฐ ์๋ ๊ฒฝ์ฐ์ ๋น๊ตํ๊ธฐ (document.querySelector("์ ํ์") vs fetch("์ฃผ์")) document.querySelector()const ์์ = document.querySelector(".ํด๋์ค์ด๋ฆ");console.log(์์) // html ์์๊ฐ ๋์จ๋ค. // ex) ๋ณ์์ ๋ด์ผ๋ฉด ์ํ๋ ๊ฒ์ด ๋์จ๋ค. fetch()const response = fetch("https://jsonplaceholder.typicode.com/todos/1");console.log(response);์ด์ํ ๋ฐ์ดํฐ๊ฐ ๋์จ๋ค. ์ด๊ฒ ๋ฐ๋ก promise ..
๐๋ชจ๋ฌ์ฐฝ ์ด์์ ๋ ๋ค์ ํ๋ฉด ๊ณ ์ ํ๊ธฐ๋ชจ๋ฌ์ฐฝ์ ์ฌ๋ ํด๋ฆญ์ด๋ฒคํธ ํจ์์ ์ ์ฉํ๊ธฐ document.body.style.overflow = "hidden"; ๋ชจ๋ฌ์ฐฝ์ ๋ซ๋ ํด๋ฆญ์ด๋ฒคํธ ํจ์์ ์ ์ฉํ๊ธฐ document.body.style.overflow = "scroll";overflow ์ค๋ช ๐ ๋ชจ๋ฌ์ฐฝ ์คํฌ๋กค๋ฐ ์ค์ .modal-content { max-height: calc(100vh - 200px); overflow-y: auto;}.modal-content::-webkit-scrollbar { display: none;} ๐overflow-y: auto; : ๋ชจ๋ฌ ๋ด๋ถ ์ปจํ ์ธ ๊ฐ ์ฃผ์ด์ง ๊ณต๊ฐ์ ๋์ด๊ฐ๋ ๊ฒฝ์ฐ ์ธ๋ก ์คํฌ๋กค๋ฐ ์์ฑํ๊ธฐ์คํฌ๋กค๋ฐ ์ปค์คํ ์ค๋ช ์ฐธ๊ณ :CSS position ์ค๋ช
๊ตฌํ ์ํฉclosest(), getAttribute()์ ์ฌ์ฉํ์ฌ ์ํ ์นด๋๋ฅผ ํด๋ฆญํ๋ฉด ํด๋น id๋ฅผ ๊ฐ์ ธ์ค๋๋ก ๊ตฌํํ์๋ค. ๊ทธ๋ผ ์ด์ ๊ทธ id๋ฅผ ๊ฐ๊ณ ๋ญ ํด์ผํ๋!์๋ง์ ๋ฐฉ์์ผ๋ก ๋ณํํ์ฌ ํ๋ฉด์ ๋์์ผ ํ๋ค. ์ ๊ณต๋ ๊ณผ์ ๋ด์ฉ์ ๋ฐ๋ฅด๋ฉด์ํ ํฌ์คํฐ์ํ ์ ๋ชฉ์ํ ๋ด์ฉํ์ ๋ถ๋งํฌ ์ถ๊ฐ ๋ฒํผ์ผ๋ก ๋ชจ๋ฌ์ฐฝ์ ๊ตฌํํด์ผ ํ๋ค. ์ด์ ๊ฑท๊ธฐ๋ฐ์์ ๋ฐฐ์ด find() ๋ฉ์๋๋ฅผ ์ด์ฉํด์ผ ํจ์ ํํฐ๋๊ป ์ ํด๋ค์๋ค๐๐ป find() ๋ฉ์๋๋?๋ฐฐ์ด์์ ์กฐ๊ฑด์ ๋ง๋ ํ๋์ ๋ด์ฉ(์์ ํน์ ๊ฐ์ฒด)๋ฅผ ์ฐพ๋ ๋ฐฉ๋ฒ์ด๋ค.๋ฐฐ์ด ๋ด์ ์์๊ฐ ๋จ์ผ ์์๋ผ๋ฉด ์กฐ๊ฑด๊ณผ ๋์ผํ ์์๊ฐ ๊ทธ๋๋ก ์ถ๋ ฅ์ด ๋๊ณ ๋ฐฐ์ด ๋ด ์์๊ฐ ๊ฐ์ฒด๋ผ๋ฉด ์กฐ๊ฑด์ ๋ถํฉํ ์์๋ฅผ ๊ฐ๊ณ ์๋ ๊ฐ์ฒด๊ฐ ๊ฐ์ฒด ํํ ๊ทธ๋๋ก ์ถ๋ ฅ๋๋ค. ๐find ์์ฑ๋ฒ๋ฐฐ์ด.find((๋ฐฐ์ด๋ด์_์์) => { r..
[ textContent / innerText / innerHTML ] ์ ์ ๋ชจ๋ ํ๊ฒ ์์์ ์ปจํ ์ธ ๋ฅผ ๊ฐ์ ธ์ค๊ฑฐ๋ ์ค์ ํ๋ ์ญํ ์ด๋ค. ์์ฑ ๋น๊ตtextContent: ๋จ์ํ ํ ์คํธ๋ง ํ์ํ๊ฑฐ๋, ์จ๊ฒจ์ง ํ ์คํธ๊น์ง ํฌํจํด์ผ ํ๋ ๊ฒฝ์ฐinnerText: ์ฌ์ฉ์์๊ฒ ๋ณด์ด๋ ํ ์คํธ๋ง ํ์ํ ๋innerHTML: ์์ ๋ด๋ถ์ HTML ํ๊ทธ์ ์ฝํ ์ธ ๋ฅผ ๋์ ์ผ๋ก ์ถ๊ฐํ๊ฑฐ๋ ์์ ํ ๋์์ฑHTML ํ๊ทธ ํฌํจ ์ฌ๋ถ์จ๊ฒจ์ง ํ ์คํธ ํฌํจ ์ฌ๋ถ์ฃผ ์ฉ๋textContentXOํ๊ทธ๋ฅผ ์ ๊ฑฐํ ์์ ํ ์คํธ ๊ฐ์ ธ์ค๊ธฐinnerTextXXํ๋ฉด์ ๋ณด์ด๋ ํ ์คํธ ๊ฐ์ ธ์ค๊ธฐinnerHTMLOOHTML ํ๊ทธ์ ํจ๊ป ๊ฐ์ ธ์ค๊ฑฐ๋ ์์ ํ๊ธฐ ๋น๊ต ์์See the Pen Untitled by ์ฑ์ฑ (@tknbwzhf-the-looper) on CodeP..
์ฃผ์ด์ง ๋ฌธ์ ๋ฐฐ๋ฌํ ๊ณ์ฐ๊ธฐ ๋ง๋ค๊ธฐ๋ฒํผ์ด ๋๋ ธ์ ๋ ์ ๋ ฅํ ์์๊ฐ์ ๋ฐ๋ฅธ ๋ฐฐ๋ฌ๋น๋ฅผ ์ถ๋ ฅํด์ผ ํ๋ค. ๐์ธํ html ๋ฐฐ๋ฌํ ๊ฒ์! ๊ฒฐ๊ณผ: ์ ๋ฌธ์ ํ์ด ๊ณผ์ ๐์๊ฐํ ๋ก์ง1. ๋ฒํผ ํด๋ฆญ ์ ์ด๋ฒคํธ ์ฃผ๊ธฐ 1-1. ํด๋ฆญ ์ ๊ณ์ฐ๊ธฐ ๊ฒฐ๊ณผ๊ฐ์ result์ ๋ํ๋ด๊ธฐ2. ๊ณ์ฐ๊ธฐ ํจ์ ์คํํ๊ธฐ 2-1. ์์๊ฐ(foodpr.value)์ ๋ฐ๋ผ ๋ฐฐ๋ฌ๋น ๊ฑฐ๋ฅด๊ธฐ ๐๊ตฌํํ ์ฝ๋const searchBtn = document.querySelector(".btn");const result = document.querySelector(".result");const foodpr = document.querySelector(".food-price");searchBtn.addEventListener("click", ..