[Devlog] JS HtmlElement.innerHTML ์‚ฌ์šฉ๋ฒ•

swingยท2023๋…„ 1์›” 9์ผ
0

[Devlog]

๋ชฉ๋ก ๋ณด๊ธฐ
3/7

๋ฌธ์ œ์ 

	const divInnerHtml = document.querySelector("div");
    let count = 1;
    const handleOnClick = () => {
      if (count % 2 === 0) {
        divInnerHtml.innerHTML("์ง์ง์ง๐Ÿ‘");
      } else {
        divInnerHtml.innerHTML("ํ™€ํ™€ํ™€๐ŸŽ…");
      }
      count += 1;
    };

์‹œ๋„ํ•ด๋ณธ ๊ฒƒ๋“ค

๐Ÿ‘‰ div์— id๋ฅผ ์ฃผ์–ด๋ด„.
๐Ÿ‘‰ innerHtml์„ innerText๋กœ ๋ฐ”๊ฟ”๋ด„.

ํ•ด๊ฒฐ

๐Ÿ‘‰ ๋””๋ฒ„๊น…๊ณผ์ •์ค‘, innerHtml๋ฉ”์„œ๋“œ๊ฐ€ ํ•จ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋ผ๋Š” ๊ฑธ ์•Œ๊ฒŒ๋จ.

	const divInnerHtml = document.querySelector("div");
    let count = 1;
    const handleOnClick = () => {
      if (count % 2 === 0) {
        divInnerHtml.innerHTML = "์ง์ง์ง๐Ÿ‘";
      } else {
        divInnerHtml.innerHTML = "ํ™€ํ™€ํ™€๐ŸŽ…";
      }
      count += 1;
    };

์•Œ๊ฒŒ ๋œ ์ 

๐Ÿ‘‰ innerHtml ๋ฉ”์„œ๋“œ๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ ๋ฐฉ์‹์ด ์•„๋‹Œ ์†์„ฑ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

profile
if(๊ธฐ๋ก๐Ÿ“) ์„ฑ์žฅ๐ŸŒฑ

0๊ฐœ์˜ ๋Œ“๊ธ€