Today I Learn 220427
์ค๋์ JavaScript์ Dom ์กฐ์์ ๋ํด ๋ฐฐ์ ๋ค.
์๊ณ ์๋ html&css ๊ฐ๋ ์ ๋์ง์ด์ค๋ ค๋ ์ข ํท๊ฐ๋ ธ๋ค.
์ด๋ฒ์ฃผ ๊ธ์์ผ์ ๋ค์ ํ ๋ฒ ์ฑ ํ์ด๋ด์ผ๊ฒ ๋ค.
์ค๋ ์ํฌ์ต ๊ณผ์ ๋ฅผ ํ๋๋ฐ ์ฝ๊ฐ ๋ด์ฉ์ด ์ดํด๊ฐ ์๋์ด์ ๊ณผ์ ํ์ดํ๋๋ฐ ์ด๋ ค์์ด ์์๋ค.
์์ฑ๊ฐ ์ง์ ํด์ฃผ๋๊ฑด ์ ํ๋๋ฐ, tag๋ฅผ ์ฐ๊ฒฐํด ์ค ๋ ์ฝ๊ฐ ํท๊ฐ๋ ธ๊ณ
// div#app ์์ ์ ํ
const divTag = document.querySelector('#app')
// h1 ํ๊ทธ๋ฅผ createElement ๋ก ์์ฑ
const h1Tag = document.createElement('h1')
// ์์ฑํ h1ํ๊ทธ์ ๋ด์ฉ์ '์ค๋์ Todo' ๋ก ์ค์
h1Tag.innerText = '์ค๋์ Todo'
divTag.append(h1Tag)
// ul, li ํ๊ทธ๋ค์ ์์ฑ ๋ฐ ๋ด์ฉ ์ถ๊ฐ
const ulTag = document.createElement('ul')
const liTag1 = document.createElement('li')
liTag1.innerText = 'homeworkํ๊ธฐ'
const liTag2 = document.createElement('li')
liTag2.innerText = 'workshopํ๊ธฐ'
ulTag.append(liTag1, liTag2)
divTag.append(ulTag)
๋ถ๋ชจ ํด๋์ค๋ฅผ ์ ์ฐ๊ฒฐํด ์ถ๋ ฅ์ด ๊ฐ๋ฅํด์ก๋ค.
๊ทธ๋ฆฌ๊ณ ๊ทธ ๋ค์ ๊ณผ์ ๋ ์ฝ๊ฐ ์ดํด๊ฐ ์๋์๋๋ฐ, ๊ฐ์ ํ๋์ฉ ๋ถ๋ฌ์์ ๋ฃ์ด์ค์ผ ํ๋๋ฐ
const cardsSection = document.querySelector('#cardsSection')
function createCard(title, content) {
// ์ฌ๊ธฐ์ ์นด๋๋ฅผ ์์ฑํ์์ค.
const Article = document.createElement("article")
Article.setAttribute("class","col-4")
const Card = document.createElement("div")
Card.setAttribute("class","card m-1")
const CardBody = document.createElement("div")
CardBody.setAttribute("class","card-body")
const CardBodyTitle = document.createElement("h5")
CardBodyTitle.setAttribute("class","card-title")
CardBodyTitle.innerText = title
const CardBodyText = document.createElement("p")
CardBodyText.setAttribute("class","card-text")
CardBodyText.innerText = content
Article.append(Card)
Card.append(CardBody)
CardBody.append(CardBodyTitle,CardBodyText)
return Article
์ด๋ฐ์์ผ๋ก ๋ฃ์ด์คฌ๋๋ฐ, ์๋ ๋ฐฉ๋ฒ์ฒ๋ผ ๋ฃ์ด์ค ์ ๋ ์์๊ฑฐ ๊ฐ๋ค.
const articleAtts = cardsSection.querySelector("article").getAttribute("class")
const newArticle = document.createElement("article")
newArticle.setAttribute("class",articleAtts)
'๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.05.02.์ (0) | 2022.05.02 |
---|---|
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.04.28.๋ชฉ (0) | 2022.05.02 |
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.04.25.์ (0) | 2022.04.25 |
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.04.22.๊ธ (0) | 2022.04.22 |
๐๐จ๐๐๐ฒ ๐ ๐๐๐๐ซ๐ง 2022.04.21.๋ชฉ (0) | 2022.04.21 |
๋๊ธ